Python3引入ssl报错(解决方案)

Python3引入ssl报错


源码编译安装python3.6 解决ssl问题

该文章作者亲测有效,环境为云服务器centos7

步骤

[root@shuai ~]# mkdir /root/Downloads
[root@shuai ~]# cd /root/Downloads/
[root@shuai Downloads]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

解包

[root@shuai Downloads]# tar zxvf Python-3.6.4.tgz

进入文件夹下

[root@shuai Downloads]# cd Python-3.6.4

使用yum来安装两个模块

yum install openssl
yum install openssl-devel -y

然后vim修改文件vim Modules/Setup,如果是一个空文件,跳过这一步,等安装完成之后再修改重新编译安装

# Socket module helper for socket(2)
_socket socketmodule.c 
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

配置编译安装目录

[root@shuai Python-3.6.4]# ./configure --prefix=/usr/local/python3

编译安装

[root@shuai Python-3.6.4]# make && make install

解决 zipimport.ZipImportError: can’t decompress data; zlib not available 的方法:

[root@shuai Python-3.6.4]#  cd /root/Downloads/
[root@shuai Downloads]# wget http://www.zlib.net/zlib-1.2.11.tar.xz
[root@shuai Downloads]# tar xvf zlib-1.2.11.tar.xz
[root@shuai Downloads]# cd zlib-1.2.11
[root@shuai zlib-1.2.11]# ./configure 
[root@shuai zlib-1.2.11]# make && make install

重新编译安装

[root@shuai Downloads]# cd Python-3.6.4
[root@shuai Python-3.6.4]# ./configure --prefix=/usr/local/python3 --with-ssl
[root@shuai Python-3.6.4]# make && make install

创建软连接

[root@shuai Python-3.6.4]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
# 创建pip3 软连接(不替换pip==python2)
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

发布了99 篇原创文章 · 获赞 34 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_42346414/article/details/90649217
今日推荐