首页 > 解决方案 > 运行 python 包失败

问题描述

编辑:我在评论部分尝试了该方法,现在问题变成了:

    Traceback (most recent call last):
  File "crawlertest.py", line 2, in <module>
    from bs4 import BeautifulSoup 
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bs4/__init__.py", line 29, in <module>
    from .builder import builder_registry
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bs4/builder/__init__.py", line 7, in <module>
    from bs4.element import (
ImportError: cannot import name 'Stylesheet'

我尝试安装 beautifulsoup4, pip3 install beautifulsoup4但它说
“无法获取 URL https://pypi.python.org/simple/beautifulsoup4/
确认 ssl 证书时出现问题:[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 警报协议版本 (_ssl.c :720)-跳过
找不到满足要求的版本beautifulsoup4(来自版本:)没有为beautifulsoup4找到匹配的发行版“
然后我尝试pip3 install --upgrade pip然后再次安装并成功。我还安装了包“请求”。
但后来当我尝试在我的 Mac 上运行 requests 和 beautifulsoup4 时,它显示如下:

    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/urllib3/connectionpool.py", line 706, in urlopen
        chunked=chunked,

和类似的东西

ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:720)
      

有什么办法可以解决吗?

标签: python

解决方案


我认为您没有安装基本证书。

去:

Macintosh HD > Applications > Python3.x

并运行安装Certificates.command

另外,请参考以下链接:

证书验证失败:无法获取本地颁发者证书

https://github.com/urllib3/urllib3/issues/1682


推荐阅读