linux下编译安装python(pip is configured with locations that require TLS/SSL, however the ssl module in P)

问题现象:

在linux中安装python后,使用pip安装第三方模块报错:

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

问题原因

  1. 当前行系统没有 openssl 或者版本比较低,一般 python3.7 需要的openssl的版本为1.0.2或者1.1.x。需要对 openssl 进行升级,并重新编译 python3.7.0。
  2. 在编译前需要修改Modules/Setup文件。

解决过程

升级openssl

# 解压缩
tar -zxvf openssl-3.0.12.tar.gz 

# 编译安装
cd openssl-3.0.12/
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
make
make install

# 备份原配置
mv /usr/bin/openssl /usr/bin/openssl.20230119.bak
mv /usr/include/openssl /usr/include/openssl.20230119.bak

# 进行配置
echo "/usr/local/ssl/lib64" > /etc/ld.so.conf.d/openssl.conf
cp /usr/local/openssl/bin/openssl /usr/bin/openssl

# 刷新内存
ldconfig -v

# 查看版本
openssl version
返回结果:OpenSSL 3.0.12 24 Oct 2023 (Library: OpenSSL 3.0.12 24 Oct 2023)

安装python3.11.6

tar -zxvf Python-3.11.6.tgz
cd Python-3.11.6/
vi Modules/Setup
# 大概在218行,找到To statically link OpenSSL一行,将下面的内容注释都打开,然后保存退出
    218 # To statically link OpenSSL:
    219  _ssl _ssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
    220      -l:libssl.a -Wl,--exclude-libs,libssl.a \
    221      -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
    222  _hashlib _hashopenssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
    223      -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a

# 编译安装python
./configure --prefix=/app/python3.11.6 --with-openssl=/usr/include/openssl
make
make install

# 验证
python3.11
import _ssl

# 不报错即可

Linux离线安装Python环境,遇到"pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available."这个错误提示,通常是由于缺少SSL模块导致的。要解决这个问题,可以按照以下步骤进行操作: 1. 首先,确认你的系统中是否已经安装了openssl和libssl-dev等相关的软件包。如果没有安装,可以使用包管理器(如apt-get、yum等)来安装这些软件包。 2. 如果已经安装了这些软件包,但仍然遇到该错误,可能是因为Python没有正确链接到SSL库。此,可以尝试重新编译安装Python。 3. 在重新编译安装Python之前,需要确保已经下载了Python源代码。你可以从Python官方网站上下载最新的稳定版本。 4. 解压源代码后,进入解压后的目录,并执行以下命令来配置编译选项: ``` ./configure --with-ssl ``` 5. 然后,执行以下命令来编译安装Python: ``` make sudo make install ``` 6. 完成安装后,你可以使用新安装Python版本来验证一下是否已经解决了SSL模块不可用的问题。可以通过以下命令来检查pip是否能正常工作: ``` python -m pip --version ``` 通过按照上述步骤重新编译安装Python,应该能够解决"pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available."这个错误,并使得pip能够正常工作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [pip is configured with locations that require TLS/SSL, however the ssl module in Python not](https://blog.csdn.net/MacWx/article/details/130365202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Ubuntu/Deepin下Python3.8出现SSL错误的解决方案](https://download.csdn.net/download/weixin_38641561/14042425)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [ pip is configured with locations that require TLS/SSL, however the ssl module in Python](https://blog.csdn.net/yuan2019035055/article/details/127078251)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值