如何解决python安装依赖库过程中报ssl错误的问题

一、报错问题复现

[root@db-master ~]# which pip3
/usr/bin/pip3
[root@db-master ~]# pip3 install request
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/request/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/request/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/request/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/request/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/request/
Could not fetch URL https://pypi.org/simple/request/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/request/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement request (from versions: none)
ERROR: No matching distribution found for request
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

二、家目录下创建pip配置文件

[root@db-master ~]# mkdir .pip

[root@db-master ~]# cd .pip/

[root@db-master ~/.pip]# vim pip.conf

使用豆瓣的源

[root@db-master ~/.pip]# cat pip.conf

[global]

timeout = 600

index-url = http://pypi.douban.com/simple/

[install]

use-mirrors = true

mirrors = http://pypi.douban.com/simple/

trusted-host = pypi.douban.com

小试牛刀,发现很爽

[root@db-master ~/.pip]# pip3 install request

WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.

Collecting request

Downloading http://pypi.doubanio.com/packages/67/fc/30193d66338a12cc1389e799a4fa27d29763cb075ced80fa2be9b2571224/request-1.0.117.tar.gz

Requirement already satisfied: requests in /usr/lib/python3.6/site-packages (from request)

Requirement already satisfied: urllib3>=1.21.1 in /usr/lib/python3.6/site-packages (from requests->request)

Installing collected packages: request

Running setup.py install for request ... done

Successfully installed request-1.0.117


三、更新pip

[root@db-master ~/.pip]# pip3 install --upgrade --trusted-host pypi.org --trusted-host files.pythonhosted.org pip

WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pip
Downloading http://pypi.doubanio.com/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
28% |█████████▏ | 491kB 995kB/s eta 0:00:0
29% |█████████▎ | 501kB 994kB/s eta 0:00:0
29% |█████████▌ | 512kB 1.5MB/s eta 0:00:0
30% |█████████▊ | 522kB 2.5MB/s eta 0:00:0
30% |█████████▉ | 532kB 2.2MB/s eta 0:00:0
31% |██████████ | 542kB 2.2MB/s eta 0:00:0
32% |██████████▎ | 552kB 2.6MB/s eta 0:00:
32% |██████████▌ | 563kB 2.7MB/s eta 0:00:
33% |██████████▋ | 573kB 3.7MB/s eta 0:00:
33% |██████████▉ | 583kB 3.7MB/s eta 0:00:
34% |███████████ | 593kB 2.6MB/s eta 0:00:
35% |███████████▏ | 604kB 1.9MB/s eta 0:00
35% |███████████▍ | 614kB 1.9MB/s eta 0:00
36% |███████████▋ | 624kB 1.9MB/s eta 0:00
36% |███████████▉ | 634kB 2.4MB/s eta 0:00
37% |████████████ | 645kB 2.4MB/s eta 0:00
38% |████████████▏ | 655kB 2.4MB/s eta 0:0
38% |████████████▍ | 665kB 2.4MB/s eta 0:0
39% |████████████▌ | 675kB 1.5MB/s eta 0:0
39% |████████████▊ | 686kB 1.4MB/s eta 0:0
40% |█████████████ | 696kB 1.7MB/s eta 0:0
40% |█████████████▏ | 706kB 2.2MB/s eta 0:
41% |█████████████▎ | 716kB 1.3MB/s eta 0:
42% |█████████████▌ | 727kB 1.3MB/s eta 0:
42% |█████████████▊ | 737kB 1.3MB/s eta 0:
43% |█████████████▉ | 747kB 1.2MB/s eta 0:
43% |██████████████ | 757kB 1.2MB/s eta 0:
44% |██████████████▎ | 768kB 1.2MB/s eta 0
45% |██████████████▌ | 778kB 1.8MB/s eta 0
45% |██████████████▋ | 788kB 1.6MB/s eta 0
46% |██████████████▉ | 798kB 1.5MB/s eta 0
46% |███████████████ | 808kB 1.5MB/s eta 0
47% |███████████████▏ | 819kB 3.1MB/s eta
48% |███████████████▍ | 829kB 3.0MB/s eta
48% |███████████████▋ | 839kB 2.7MB/s eta
49% |███████████████▉ | 849kB 3.3MB/s eta
49% |████████████████ | 860kB 3.6MB/s eta
50% |████████████████▏ | 870kB 3.6MB/s eta
51% |████████████████▍ | 880kB 3.6MB/s eta
51% |████████████████▌ | 890kB 4.0MB/s eta
52% |████████████████▊ | 901kB 4.3MB/s eta
52% |█████████████████ | 911kB 4.3MB/s eta
53% |█████████████████ | 921kB 4.3MB/s eta
54% |█████████████████▎ | 931kB 3.9MB/s et
54% |█████████████████▌ | 942kB 4.3MB/s et
55% |█████████████████▊ | 952kB 2.7MB/s et
55% |█████████████████▉ | 962kB 2.2MB/s et
56% |██████████████████ | 972kB 2.1MB/s et
57% |██████████████████▎ | 983kB 2.1MB/s e
57% |██████████████████▍ | 993kB 2.4MB/s e
58% |██████████████████▋ | 1.0MB 2.4MB/s e
58% |██████████████████▉ | 1.0MB 1.3MB/s e
59% |███████████████████ | 1.0MB 1.3MB/s e
60% |███████████████████▏ | 1.0MB 1.4MB/s
60% |███████████████████▍ | 1.0MB 1.4MB/s
61% |███████████████████▋ | 1.1MB 1.8MB/s
61% |███████████████████▊ | 1.1MB 2.2MB/s
62% |████████████████████ | 1.1MB 1.6MB/s
62% |████████████████████▏ | 1.1MB 1.5MB/s
63% |████████████████████▍ | 1.1MB 1.5MB/s
64% |████████████████████▌ | 1.1MB 1.5MB/s
64% |████████████████████▊ | 1.1MB 3.1MB/s
65% |█████████████████████ | 1.1MB 3.1MB/s
65% |█████████████████████ | 1.1MB 2.2MB/s
66% |█████████████████████▎ | 1.1MB 2.2MB/
67% |█████████████████████▌ | 1.2MB 2.2MB/
67% |█████████████████████▊ | 1.2MB 2.1MB/
68% |█████████████████████▉ | 1.2MB 3.3MB/
68% |██████████████████████ | 1.2MB 1.9MB/
69% |██████████████████████▎ | 1.2MB 1.8MB
70% |██████████████████████▍ | 1.2MB 1.8MB
70% |██████████████████████▋ | 1.2MB 1.8MB
71% |██████████████████████▉ | 1.2MB 1.8MB
71% |███████████████████████ | 1.2MB 2.2MB
72% |███████████████████████▏ | 1.2MB 1.9M
73% |███████████████████████▍ | 1.3MB 1.8M
73% |███████████████████████▋ | 1.3MB 1.9M
74% |███████████████████████▊ | 1.3MB 1.9M
74% |████████████████████████ | 1.3MB 3.1M
75% |████████████████████████▏ | 1.3MB 3.3
76% |████████████████████████▍ | 1.3MB 2.6
76% |████████████████████████▌ | 1.3MB 2.7
77% |████████████████████████▊ | 1.3MB 2.8
77% |█████████████████████████ | 1.3MB 2.9
78% |█████████████████████████ | 1.4MB 3.4
79% |█████████████████████████▎ | 1.4MB 3.
79% |█████████████████████████▌ | 1.4MB 2.
80% |█████████████████████████▋ | 1.4MB 2.
80% |█████████████████████████▉ | 1.4MB 2.
81% |██████████████████████████ | 1.4MB 2.
81% |██████████████████████████▎ | 1.4MB 2
82% |██████████████████████████▍ | 1.4MB 2
83% |██████████████████████████▋ | 1.4MB 1
83% |██████████████████████████▉ | 1.4MB 1
84% |███████████████████████████ | 1.5MB 2
84% |███████████████████████████▏ | 1.5MB
85% |███████████████████████████▍ | 1.5MB
86% |███████████████████████████▋ | 1.5MB
86% |███████████████████████████▊ | 1.5MB
87% |████████████████████████████ | 1.5MB
87% |████████████████████████████▏ | 1.5MB
88% |████████████████████████████▎ | 1.5MB
89% |████████████████████████████▌ | 1.5MB
89% |████████████████████████████▊ | 1.5MB
90% |█████████████████████████████ | 1.6MB
90% |█████████████████████████████ | 1.6MB
91% |█████████████████████████████▎ | 1.6M
92% |█████████████████████████████▌ | 1.6M
92% |█████████████████████████████▋ | 1.6M
93% |█████████████████████████████▉ | 1.6M
93% |██████████████████████████████ | 1.6M
94% |██████████████████████████████▎ | 1.6
95% |██████████████████████████████▍ | 1.6
95% |██████████████████████████████▋ | 1.6
96% |██████████████████████████████▉ | 1.7
96% |███████████████████████████████ | 1.7
97% |███████████████████████████████▏| 1.
98% |███████████████████████████████▍| 1.
98% |███████████████████████████████▋| 1.
99% |███████████████████████████████▊| 1.
99% |████████████████████████████████| 1.
100% |████████████████████████████████| 1.7MB 3.9MB/s
Installing collected packages: pip
Successfully installed pip-21.3.1
You are using pip version 21.3.1, however version 22.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

[root@db-master ~/.pip]# pip -V

pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

[root@db-master ~/.pip]# pip3 -V

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.

Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.

To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

[root@db-master ~/.pip]#

OK,大家如果遇到的话可以按此方法解决。

迁移python依赖库

首先要确保新旧服务器的python环境一致,操作如下:

1、导出依赖库

[root@db-master ~/.pip]# pip freeze > /tmp/requirements.txt

[root@db-master ~/.pip]# cat /tmp/requirements.txt

cached-property==1.5.1

。。。

2、在新服务器上安装

[root@db-master ~/.pip]# scp /tmp/requirements.txt db-slave:~

[root@db-slave ~]# pip3 install -r requirements.txt

Looking in indexes: http://pypi.douban.com/simple/

Collecting cached-property==1.5.1

Downloading http://pypi.doubanio.com/packages/3b/86/85c1be2e8db9e13ef9a350aecd6dea292bd612fa288c2f40d035bb750ded/cached_property-1.5.1-py2.py3-none-any.whl (6.0 kB)

Collecting chardet==3.0.4

。。。

举报
评论 0