当前位置:   article > 正文

CentOS 7安装Python 3.6,pip3报错问题_centos 7 pip3 [root@root ~]# pip3 list traceback (

centos 7 pip3 [root@root ~]# pip3 list traceback (most recent call last): fi

在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>


是因为没有正确配置ssl的原因,经过多次实验,总结一下正确安装步骤。

安装步骤:

1. 下载Python 3.6.3

https://www.python.org/downloads/source/

2. 解压缩

.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

4. 添加lib读取路径

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

其中SSL=后面的路径是你实际安装openssl的路径


6. 配置安装

./configure --prefix=/usr/Python3.6.3
make
make install

如果在安装过程中,报找不到libssl.so.1.1的错误,请检查第3步和第4步的配置。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/570213
推荐阅读
相关标签
  

闽ICP备14008679号