pip 无法与 pypi 服务器建立安全连接
pip fails to make a secure connection to pypi server
昨天我尝试用 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)
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 update-ca-certificates
我的问题略有不同。 https://pypi.python.org/simple/ 证书似乎已于 2016 年 6 月续订,因此如果您的 OS 日期早于该日期,您将无法验证证书,无论是否有正确的 CA 证书安装。
昨天我尝试用 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)
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 update-ca-certificates
我的问题略有不同。 https://pypi.python.org/simple/ 证书似乎已于 2016 年 6 月续订,因此如果您的 OS 日期早于该日期,您将无法验证证书,无论是否有正确的 CA 证书安装。