赞
踩
在CentOS 7上安装Python3.6.3后,在使用pip命令时报如下错误
Traceback (most recent call last):
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/commands/search.py", line 45, in run
pypi_hits = self.search(query, options)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/commands/search.py", line 62, in search
hits = pypi.search({'name': query, 'summary': query}, 'or')
File "/usr/Python3.6.3/lib/python3.6/xmlrpc/client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "/usr/Python3.6.3/lib/python3.6/xmlrpc/client.py", line 1452, in __request
verbose=self.__verbose
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/download.py", line 775, in request
headers=headers, stream=True)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 522, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/download.py", line 386, in request
return super(PipSession, self).request(method, url, *args, **kwargs)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
resp = self.send(prep, **send_kwargs)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 596, in send
r = adapter.send(request, **kwargs)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send
resp = super(CacheControlAdapter, self).send(request, **kw)
File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/adapters.py", line 497, in send
raise SSLError(e, request=request)
<span style="color:#ff0000;">pip._vendor.requests.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.</span>
安装步骤:
1. 下载Python 3.6.3
https://www.python.org/downloads/source/
.xz文件需要用xz工具解压缩,先安装xz
sudo yum install xz
xz d Python-3.6.3.tar.xz
tar xvf Python-3.6.3.tar
3. 下载/安装 openssl和openssl-devel。没有wget的可通过yum install wget安装
wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz
在CentOS 7的最小安装时,会默认安装openssl,但是我没找到安装的lib路径,所以就将其卸载了,自己装,因为路径在安装Python3.6时需要用到。卸载openssl的命令:
sudo yum erase openssl
安装openssl:
tar zxvf openssl-1.1.0g.tar.gz
cd openssl-1.1.0g
./config --prefix=/usr/local/openssl
make
make install
其中 --prefix后的路径就是将要安装的目录,记住下面要用到。下载openssl-devel并安装
sudo yum install openssl-devel
sudo vi /etc/ld.so.conf
在最后添加一行
/usr/local/openssl/lib
这个路径就是刚才安装openssl的路径。然后执行下面的命令使其生效
sudo ldconfig
5. 修改Python安装包里的Modules/Setup.dist文件,将ssl注释掉的部分打开,修改后内容如下:
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/openssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
./configure --prefix=/usr/Python3.6.3
make
make install
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。