Python pip无法与pypi服务器建立安全连接
昨天我尝试用pip安装一些python软件包,但它就是不起作用Python pip无法与pypi服务器建立安全连接,python,ubuntu,ssl,pip,Python,Ubuntu,Ssl,Pip,昨天我尝试用pip安装一些python软件包,但它就是不起作用 paquete@paquete-ultrabook:~$ pip install isort -v Downloading/unpacking isort Could not fetch URL https://pypi.python.org/simple/isort/: connection error: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)
paquete@paquete-ultrabook:~$ pip install isort -v
Downloading/unpacking isort
Could not fetch URL https://pypi.python.org/simple/isort/: connection error: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)
Will skip URL https://pypi.python.org/simple/isort/ when looking for download links for isort
Could not fetch URL https://pypi.python.org/simple/: connection error: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)
Will skip URL https://pypi.python.org/simple/ when looking for download links for isort
Cannot fetch index base URL https://pypi.python.org/simple/
Could not fetch URL https://pypi.python.org/simple/isort/: connection error: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)
Will skip URL https://pypi.python.org/simple/isort/ when looking for download links for isort
Could not find any downloads that satisfy the requirement isort
Cleaning up...
Removing temporary dir /tmp/pip_build_paquete...
No distributions at all found for isort
Exception information:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1177, in prepare_files
url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 277, in find_requirement
raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for isort
Storing debug log for failure in /tmp/tmpl86YQE
我一直在网上到处寻找答案,但没有成功。2012年的很多答案都建议降级,但自那以后,麻烦的bug已经修复
paquete@paquete-ultrabook:~$ pip -V
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
有些人的python解释器有问题,但它与服务器的连接似乎很好
paquete@paquete-ultrabook:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib
>>> conn = httplib.HTTPSConnection("pypi.python.org")
>>> conn.request("GET","/simple/")
>>> res = conn.getresponse()
>>> print res.status, res.reason
200 OK
作为补充信息,我在几周前进行了elementaryos全新安装。所有包都会发生这种情况。我已经通过apt安装了所有东西,所以这似乎有什么想法
更新
根据@andersson的建议,我尝试安装pip的最新版本。然后这个突然冒了出来
paquete@paquete-ultrabook:~$ sudo python3 Downloads/get-pip.py -v
The directory '/home/paquete/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/paquete/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Starting new HTTPS connection (1): pypi.python.org
There was an error checking the latest version of pip
Traceback (most recent call last):
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py", line 253, in ssl_wrap_socket
context.load_verify_locations(ca_certs)
ssl.SSLError: unknown error (_ssl.c:2734)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/adapters.py", line 370, in send
timeout=timeout
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
body=body, headers=headers)
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
self._validate_conn(conn)
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 762, in _validate_conn
conn.connect()
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
ssl_version=resolved_ssl_version)
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py", line 255, in ssl_wrap_socket
raise SSLError(e)
pip._vendor.requests.packages.urllib3.exceptions.SSLError: unknown error (_ssl.c:2734)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/tmp8w985p0e/pip.zip/pip/utils/outdated.py", line 126, in pip_version_check
headers={"Accept": "application/json"},
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/sessions.py", line 476, in get
return self.request('GET', url, **kwargs)
File "/tmp/tmp8w985p0e/pip.zip/pip/download.py", line 367, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/sessions.py", line 464, in request
resp = self.send(prep, **send_kwargs)
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/cachecontrol/adapter.py", line 46, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/adapters.py", line 431, in send
raise SSLError(e, request=request)
pip._vendor.requests.exceptions.SSLError: unknown error (_ssl.c:2734)
这似乎是一个一般性问题。我对默认(1.5.4)pip版本也有一些问题。您能否成功地将pip更新到最新(6.1.1)版本,或者您已经尝试过,但两个pip版本的安装都失败了?立即通过以下方式解决:
sudo更新ca证书
我的问题略有不同。证书似乎是在2016年6月更新的,因此,如果您的操作系统的日期早于该日期,则无论是否安装了正确的CA证书,您都会在验证证书时遇到问题。我有点高兴,不仅仅是我。在运行get-pip.py时,出现了以下步骤/tmp/tmpRJjSJP/pip.zip/pip/_vendor/requests/packages/urlib3/util/ssl.py:79:UnsecurePlatformWarning:真正的SSLContext对象不可用。这会阻止urllib3正确配置SSL,并可能导致某些SSL连接失败。有关详细信息,请参阅。我将对此进行深入探讨。为了增加更多的神秘感,一个旧的virtualenv pip可以很好地工作。