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

在centos上面安装python3.7之后,运行pip3的时候提示如下错误:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

搜索整个网页都没有解决办法,实在没有办法又安装了anaconda才解决pip install 的问题。
下面是从网上找的一些可以借鉴的方法,虽然对我来说没有意义,但是还是希望收藏。

Python3安装成功后,也能与2.6.6版并存。

但接下来通过pip(注:因为是Python3,所以实际使用pip3命令)安装pymysql、requests时提示错误:

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

#pip3 install pymysql
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pymysql
  Could not fetch URL https://pypi.python.org/simple/pymysql/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement pymysql (from versions: )
No matching distribution found for pymysql

网上查找资料,第一种方案提示说,需要在make前,./configure那一步加一个“–with-ssl”的参数,但实际执行"./configure --with-ssl"后提示“configure: WARNING: unrecognized options: --with-ssl”。

划重点!

后来找到第二种方案,实测可行,需要在make前修改Modules/Setup文件,完整编译步骤如下:

cd Python-3.6.2

make clean #如果已经和我一样编译过一次,建议先执行此步骤,否则可省略。

./configure prefix=/usr/local/python3

修改./Modules/Setup文件(将如下四行的注释去掉):

# 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

此外,因为用到的lib路径是/usr/local/ssl,而默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件,所以还需要做以下事情:

vim /etc/ld.so.conf(这个文件记录了编译时使用的动态链接库的路径)

增加一行:/usr/local/ssl/lib(注:也可能已有,只需把双引号去掉)

并执行 /sbin/ldconfig -v命令

make && make install

到此Python3重新编译成功,并且再通过pip3安装pymysql、requests等库就不会提示如标题的错误了。

最后,执行Python操作数据库的脚本,验证一下环境是否正确。
————————————————
版权声明:本文为CSDN博主「企鹅Sheldon」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Pc620/article/details/86163275

  • 10
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值