一、PIP3安装提示SSL
服务器centos6由于服务器需要安装pymysql,于是用之前单独编译的python3的pip3安装(PS:因为不想破坏系统的PYTHON2所以单独编译了PYTHON3)
1 |
pip3 install pymysql -i http://mirrors.aliyun.com/pypi/simple |
出现报错:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
开始以为是openssl版本过低导致,把openssl升级到最新,并且替换了系统的版本以后,发现依然提示这个.最后发现报错信息还有:
The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
PS:而且看网上有人说PYTHON是从3.7开始要求openssl1.0.2+版本的,centos6默认是1.0.1e版本要升级.
二、解决方法
直接修改一下安装命令:
1 |
pip3 install pymysql -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com |
pip3参数-i是指定安装源,--trusted-host是信任源
就安装好了,感觉整个人都被openssl忽悠了.顺便把升级OPENSSL和重编译PYTHON3遇到的问题也发上来记录一下:
三、操作记录
编译PYTHON3和PIP3
安装编译环境
1 |
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel |
下载PYTHON3,解压编译,添加系统命令为python3和pip3
1 2 3 4 5 6 7 8 |
cd /usr/local/src/ wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz tar -zxvf Python-3.7.0.tgz cd Python-3.7.0 ./configure --prefix=/usr/local/python3 make && make install ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3 |
更新openssl(--prefix指定一下安装目录,否则默认会装到/usr/local/)
下载安装openssl
1 2 3 4 5 6 |
cd /usr/local/src/ wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz tar xf openssl-1.1.1k.tar.gz cd openssl-1.1.1k ./config --prefix=/usr/local/openssl make && make install |
更新系统openssl
1 2 3 4 5 6 |
echo "/usr/local/lib64/" >> /etc/ld.so.conf ldconfig mv /usr/bin/openssl /usr/bin/openssl.old mv /usr/include/openssl /usr/include/openssl.bak ln -s /usr/local/bin/openssl /usr/bin/openssl ln -s /usr/local/include/openssl /usr/include/openssl |
到这里系统执行openssl version已经是1.1.1k版本
重新编译PYTHON3(configure指定openssl目录为上面编译安装openssl的目录)
1 2 3 4 |
cd /usr/local/src/Python-3.7.0 make clean make distclean ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl |
注意看最后的提示X509是否是YES
结果发现还是NO,要更新一下系统的so文件(有个坑,请看完再执行,我是64位系统,32位系统可能在/usr/lib/下面,我不确定)
1 2 3 4 |
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old mv /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.10.old ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.10 |
执行完以后.运行下pip检测下版本(这个是系统自带的python2的pip)
1 |
pip -V |
提示报错
1 |
ImportError: /usr/lib64/libssl.so.10: version `libssl.so.10' not found (required by /usr/lib64/python2.6/lib-dynload/_hashlib.so) |
只能把libssl.so.10修改回来
1 2 |
mv /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.10.new mv /usr/lib64/libssl.so.10.old /usr/lib64/libssl.so.10 |
再执行
1 2 |
pip -V pip3 -V |
提示正常
1 2 |
pip 7.1.0 from /usr/lib/python2.6/site-packages (python 2.6) pip 10.0.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7) |
然后再次configure,X509总算提示YES了(PS:也不知道python是如何使用系统的openssl的so动态文件的)
然后打开ssl编译配置(网上有的说configure的时候带--with-ssl参数,但是我测试好像没用)
1 2 |
vim Modules/Setup vim Modules/Setup.dist |
取消下面的这些注释(删除前面的#)
1 2 3 4 |
SSL=/usr/local/ssl _ssl _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto |
然后把SSL修改成之前编译安装openssl的路径
1 |
SSL=/usr/local/openssl |
也有说要设置环境变量的
1 2 3 |
export LDFLAGS=" -L/usr/local/openssl/lib" export CPPFLAGS=" -I/usr/local/openssl/include" export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig" |
然后编译,编译的时候要
1 2 |
make make install |
结果又提示已经存在这2个目录无法安装.
1 2 |
/usr/local/python3/lib/python3.7/site-packages/pip-10.0.1.dist-info /usr/local/python3/lib/python3.7/site-packages/setuptools-39.0.1.dist-info |
办法就是删除这2个目录,不放心的可以改名一下
1 2 3 |
cd /usr/local/python3/lib/python3.7/site-packages mv pip-10.0.1.dist-info pip-10.0.1.dist-info.bak mv setuptools-39.0.1.dist-info setuptools-39.0.1.dist-info.bak |
然后再
1 |
make install |
总算重新编译成功了PYTHON3
结果执行文章开头的那句依然提示
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
最后还是用--trusted-host解决了.很可能一上来就不是openssl版本问题.
这里再提一点,就算configure里X509提示了YES,但是重新编译安装好的PYTHON3依然无法import ssl,提示仍然找不到ssl模块,但是在make的目录里的PYTHON3启动可以正常import ssl.也不知道是安装问题还是环境变量问题.