centos 安装pip 报错

在CentOS上安装pip时遇到SSL错误,提示无法连接HTTPS URL。解决方案包括检查openssl和openssl-devel的安装状态,如未安装则安装,已安装则重新编译Python,取消Setup文件中关于SSL的注释,然后重新编译并安装。完成这些步骤后,pip安装将恢复正常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载get-pip.py文件后
用python get-pip.py 安装报以下错误:

pip is configured with locations that require TLS/SSL, however the ssl
module in Python is not available. Collecting xxx Could not fetch
URL https://pypi.python.org/simple/xxxx/: 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 xxx (from versions: ) No matching
distribution found for xxx

执行python ,进入python 命令行:

import ssl 
Traceback (most recent call last): 
File “”, line 1, in 
File “/usr/local/python27/lib/python2.7/ssl.py”, line 60, in 
import _ssl # if we can’t import it, let the error propagate 
ImportError: No module named _ssl

查看是否安装openssl 和 openssl-devel

[xxx@xxx ~]# rpm -aq|grep openssl 
openssl-x.x.xe-x.xxx
openssl-devel-xxx-xxx

如果没有安装就重新安装下这两个包,如果已经安装,重新编译下python

重新编译python
修改Setup文件
vim /{python源码目录}/Python-2.x.x/Modules/Setup
找到下面这几行,把注释去掉。

SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

重新执行
make
make install

这时进入python 命令行, import ssl 就可以正常使用了。
python get-pip.py也不会报上面的错误了

http://blog.youkuaiyun.com/qq_25560423/article/details/62055497
https://github.com/pypa/pip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值