Pip安装失败:需要SSL

时间:2017-11-03 00:31:40

标签: python dependencies pip rsa

Collecting rsa==3.1.1 (from -r /racetrack/.requirements.txt (line 41))
eval (python -m virtualfish)
  Downloading rsa-3.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.10.tar.gz
    Traceback (most recent call last):          
      File "/usr/lib/python2.7/urllib2.py", line 558, in http_error_default
        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    urllib2.HTTPError: HTTP Error 403: SSL is required

5 个答案:

答案 0 :(得分:9)

解决方案:升级到您图书馆的最新版本。

一切都从这里开始,突然(2017年10月)Distutils团队决定撤销对非https请求的支持,而不必担心破坏许多python库的早期版本的向后兼容性。有点不专业,但嘿,这是Python世界。

所以这是修复,只需转到最新版本的库(在我的情况下为rsa==3.4.2)在任何库(nltk==3.2.5等)上

替代解决方案:fork(或本地复制)repo&的版本将http网址修改为https

但是,请注意您是否在维护另一个项目时执行此操作,因为您升级的依赖项可能与作者预期的原始库不兼容,例如在我的上下文中rsa在另一个库下使用作为依赖。因此,解决方案是升级父库,以便自动处理此问题。

答案 1 :(得分:5)

不幸的是,先前的答案对我都不起作用。

恕我直言,这是非常愚蠢的点子/ distutils选择破坏http存储库中的软件包。

我认为一个更好的选择是:

  • pip / distutils默认使用https

  • 在出现错误(例如403)的情况下,pip必须建议您“软件包存储库位于http上,您要下载吗?”

直到2020年,许多Python 2软件包仍在http repos上。经过他们的决定,这些软件包的安装被破坏了。


对我来说,可行的解决方案是一个非常简单的python核心模块补丁:

--- /usr/local/lib/python2.7/urllib2.py.original
+++ /usr/local/lib/python2.7/urllib2.py
@@ -427,6 +427,9 @@
             req = meth(req)

         response = self._open(req, data)
+        if protocol == "http" and response.code == 403 :
+            if isinstance(fullurl, basestring) and fullurl.startswith("http://pypi.python.org/packages/source/d/distribute/") :
+                return    self.open(fullurl.replace("http://", "https://"), data = data, timeout = timeout)

         # post-process response
         meth_name = protocol+"_response"

有效:如果失败的网址位于http上,请重试https。

我知道它有点丑陋,但是它非常清楚,您还可以快速恢复到原始模块(制作 /usr/local/lib/python2.7/urllib2.py的副本之前)。

答案 2 :(得分:1)

在我的情况下(在较老的Raspbian上),接受的答案不起作用,但是如this帖子中所述,提供带有命令的下载URL对我有帮助:

sudo pip install paho-mqtt -i https://pypi.python.org/simple

答案 3 :(得分:0)

使用easy_install而不是pip为我工作:

easy_install funkload

我试图pip install funkload并且正在尝试:

Collecting funkload
  Using cached funkload-1.17.1.tar.gz
  Complete output from command python setup.py egg_info:
  Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.14.tar.gz
  Traceback (most recent call last):
...<snip>
  urllib2.HTTPError: HTTP Error 403: SSL is required

由于funkload的日期是2011年,旧的easy_install可以使用。

答案 4 :(得分:0)

只需easy_install rsa==3.1.1即可完成工作。