原地址:https://www.jianshu.com/p/3ec24f563b81
centos安装python3.7时遇到如下问题,查阅知需要的openssl版本最低为1.0.2,但是centos 默认的为1.0.1,所以需要重新更新openssl
import _ssl # if we can't import it, let the error propagate ImportError: No module named _ssl
安装依赖库
yum install -y zlib zlib-dev openssl-devel sqlite-devel bzip2-devel libffi libffi-devel gcc gcc-c++
安装openssl
# 注意:openssl编译的时候,需要bzip2库,并且版本要匹配 wget http://www.openssl.org/source/openssl-1.1.1.tar.gz tar -zxvf openssl-1.1.1.tar.gz cd openssl-1.1.1 ./config --prefix=$HOME/openssl shared zlib make && make install
设置环境变量LD_LIBRARY_PATH
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/openssl/lib" >> $HOME/.bash_profile source $HOME/.bash_profile
这一步一定要有!!LD_LIBRARY_PATH环境变量主要用于指定查找共享库(动态链接库)时除了默认路径之外的其他路径。当执行函数动态链接.so时,如果此文件不在缺省目录下‘/lib' and ‘/usr/lib',那么就需要指定环境变量LD_LIBRARY_PATH
解压python3.7,并安装,一定要指定刚才安装的1.1.1版本的openssl!!!
解压python3.7,并安装,一定要指定刚才安装的1.1.1版本的openssl!!!
tar -zxvf Python-3.7.0.tgz ./configure --prefix=$HOME/Py37 --with-openssl=$HOME/openssl make && make install echo $HOME
至此python3.7就安装完了,来检验下ssl模块能否被导入吧:
[root@izbp12am8wqrn7t6wzgmydz Python-3.7.0]# echo $HOME /root [root@izbp12am8wqrn7t6wzgmydz Python-3.7.0]# cd /root/Py37/ [root@izbp12am8wqrn7t6wzgmydz bin]# ./python3 Python 3.7.0 (default, Sep 16 2018, 14:12:43) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import ssl >>> import _ssl >>>
查看源python的路径
whereis python
需要更新软链接