pip安装依赖时报ssl的问题
文章发布较早,内容可能过时,阅读注意甄别。
这个问题之前遇到过一次,也记录过解决的办法,没想到最近又安装项目,之前记录的办法竟然也不管用了。今天再来记录一下新找到的解决办法。
# 1,老版笔记。
pip 进行安装的时候,总是报 ssl 的问题,可能是源的问题。
报错信息如下:
Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)'),))
1
网上有说安装方式用:
1.pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org pythonPackageName
2.pip --trusted-host pypi.python.org install pythonPackageName
1
2
2
其中 "pythonPackageName" 是你要安装的库名称(比如:requests、lxml 等)
然而经过测试发现并不行。
于是采用豆瓣源进行安装:
pip3 install requests -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com aioredis==1.1.0
1
但是这个也只是单个安装的时候没有问题,用-r 进行安装又不行了。
于是写入到配置里边:
mkdir /root/.pip
cat > ~/.pip/pip.conf <<EOF
[global]
timeout = 60
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
EOF
1
2
3
4
5
6
7
2
3
4
5
6
7
然后直接pip install pack
即可。
但是发现还会报错。
祭出神器
:
for packge in $(cat requirements.txt);do pip install requests -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com $packge ;done
1
这个确实是神器,非常好用!
# 2,安装遇到 ssl 问题。
[root@localhost ~]$pip install docker
Collecting docker
Could not fetch URL https://pypi.python.org/simple/docker/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)- skipping
Could not find a version that satisfies the requirement docker (from versions: )
No matching distribution found for docker
1
2
3
4
5
2
3
4
5
解决办法:
mkdir .pip
cd .pip
1
2
2
然后新增配置文件。
vi pip.conf
[global]
timeout = 6000
index-url = http://pypi.douban.com/simple/
[install]
use-mirrors = true
mirrors = http://pypi.douban.com/simple/
trusted-host = pypi.douban.com
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
然后咋 pip install 就好了。
[root@localhost .pip]$pip install docker
Collecting docker
Downloading http://pypi.doubanio.com/packages/06/0b/ce97eb31058eddaef316973b8299b737ebab0bcb5798fd5a3225d53b4455/docker-3.5.0-py2.py3-none-any.whl (125kB)
100% |████████████████████████████████| 133kB 1.4MB/s
Collecting docker-pycreds>=0.3.0 (from docker)
Downloading http://pypi.doubanio.com/packages/ea/bf/7e70aeebc40407fbdb96fa9f79fc8e4722ea889a99378303e3bcc73f4ab5/docker_pycreds-0.3.0-py2.py3-none-any.whl
Collecting requests!=2.18.0,>=2.14.2 (from docker)
Downloading http://pypi.doubanio.com/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)
100% |████████████████████████████████| 92kB 14.0MB/s
Collecting websocket-client>=0.32.0 (from docker)
Downloading http://pypi.doubanio.com/packages/14/d4/6a8cd4e7f67da465108c7cc0a307a1c5da7e2cdf497330b682069b1d4758/websocket_client-0.53.0-py2.py3-none-any.whl (198kB)
100% |████████████████████████████████| 204kB 3.4MB/s
Collecting six>=1.4.0 (from docker)
Downloading http://pypi.doubanio.com/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting urllib3<1.24,>=1.21.1 (from requests!=2.18.0,>=2.14.2->docker)
Downloading http://pypi.doubanio.com/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 12.9MB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests!=2.18.0,>=2.14.2->docker)
Downloading http://pypi.doubanio.com/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 12.9MB/s
Collecting idna<2.8,>=2.5 (from requests!=2.18.0,>=2.14.2->docker)
Downloading http://pypi.doubanio.com/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
100% |████████████████████████████████| 61kB 18.1MB/s
Collecting certifi>=2017.4.17 (from requests!=2.18.0,>=2.14.2->docker)
Downloading http://pypi.doubanio.com/packages/df/f7/04fee6ac349e915b82171f8e23cee63644d83663b34c539f7a09aed18f9e/certifi-2018.8.24-py2.py3-none-any.whl (147kB)
100% |████████████████████████████████| 153kB 12.5MB/s
Installing collected packages: six, docker-pycreds, urllib3, chardet, idna, certifi, requests, websocket-client, docker
Successfully installed certifi-2018.8.24 chardet-3.0.4 docker-3.5.0 docker-pycreds-0.3.0 idna-2.7 requests-2.19.1 six-1.11.0 urllib3-1.23 websocket-client-0.53.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 3,升级 pip 一直报错
[root@localhost ~]$pip install --upgrade pip
Collecting pip
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 307, in run
requirement_set.prepare_files(finder)
File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 370, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 587, in _prepare_file
session=self.session, hashes=hashes)
File "/usr/lib/python2.7/site-packages/pip/download.py", line 810, in unpack_url
hashes=hashes
File "/usr/lib/python2.7/site-packages/pip/download.py", line 649, in unpack_http_url
hashes)
File "/usr/lib/python2.7/site-packages/pip/download.py", line 842, in _download_http_url
stream=True,
File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 487, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python2.7/site-packages/pip/download.py", line 378, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 585, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 46, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 477, in send
raise SSLError(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)
You are using pip version 8.1.2, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
这个时候用如下命令更新:
[root@localhost ~]$pip install --upgrade --trusted-host pypi.org --trusted-host files.pythonhosted.org pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/8d/07/f7d7ced2f97ca3098c16565efbe6b15fafcba53e8d9bdb431e09140514b0/pip-19.2.2-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 134kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Successfully installed pip-19.2.2
[root@localhost ~]$pip -V
pip 19.2.2 from /usr/lib/python2.7/site-packages/pip (python 2.7)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
上次更新: 2024/11/28, 21:21:13