Loading

python36源码编译后无法通过pip安装软件

Python-3.6.2

最近在Ubuntu17.04上安装Python3.6之后,使用pip命令出现了问题,提示说找不到ssl模块,出现错误如下:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Could not fetch URL https:*******: There was a problem confirming the ssl certificate: 
Can't connect to HTTPS URL because the SSL module is not available. - skipping

安装Python3.6的操作如下

wget获取安装包:
wget http://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz

解压安装包:
tar -xvzf Python-3.6.2.tgz

检查安装平台属性,系统是否有编译时所需要额库,以及库的版本是否满足编译需要
./configure --prefix=/usr/local/python36

编译源码
make

成功编译之后,安装
sudo make install

在安装完之后,我们希望用pip3命令来安装pymysql。首先,用如下命令安装pip3:

cd /usr/local/python36/bin/ && ./pip3.6 install pymysql

但是此时就出错了,显示本文开始提到的错误,大致意思就是安装过程需要SSL,但是那个SSL找不到。

在./configure过程中,如果没有加上–with-ssl参数时,默认安装的软件涉及到ssl的功能不可用,刚好pip3过程需要ssl模块,而由于没有指定,所以该功能不可用

解决办法是重新对python3.6进行编译安装,用一下过程来实现编译安装:

apt install openssl libssl-dev
cdPython-3.6.2
./configure --prefix=/usr/local/python36 --with-ssl
make
sudo make install

 

python 3.6.4 配置ssl

 yum install openssl-devel -y
vi /usr/local/Python-3.6.4/Modules/Setup
#修改结果如下:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

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

  

posted @ 2018-01-22 11:21  月夫  阅读(125)  评论(0)    收藏  举报