如何修复CentOs中“Python中的ssl模块不可用”

问题描述 投票:0回答:10

在 GoDaddy VPS CentOs 7 上安装新的 Python 3.7.1。 尝试 pip3 install virtualenv 或 python 3 -m pip install virtualenv 并获取:

pip 配置了需要 TLS/SSL 的位置,但是 Python 中的 ssl 模块不可用。

openssl-devel 已安装且是最新的

这个问题已经被问过并回答过很多次了,但是我找到的解决方案并没有解决我的问题。 谢谢大家!

我尝试了以下基于 CentOs 和 Linux 的解决方案:

使用 pip3 安装包时“Python 中的 SSL 模块不可用” # 允许构建 python ssl 库 yum 安装 openssl-devel # 下载any python版本的源码 cd /usr/src wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz tar xf Python-3.7.1.tar.xz cd Python-3.7.1

  # Configure the build w/ your installed libraries
  ./configure

  # Install into /usr/local/bin/python3.6, don't overwrite global python bin
  make altinstall

尝试使用 Python 3.7.2 pip 安装软件包会导致 TSL/SSL 错误

使用 pip3 安装包时出现“Python 中的 SSL 模块不可用”

pip 配置了需要 TLS/SSL 的位置,但是 Python 中的 ssl 模块不可用

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

pip 无法确认 SSL 证书:SSL 模块不可用

“Python 中的 ssl 模块不可用”pip 无法确认 SSL 证书:SSL 模块不可用

  `uncommented suggestions for CentOs
  make install failed:
    gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration   -I. -I./Include     -DUSE_SSL -I/include -I/include/openssl -c ./Modules/_ssl.c -o Modules/_ssl.o
    ./Modules/_ssl.c:74:6: error: #error "libssl is too old and does not support X509_VERIFY_PARAM_set1_host()"
    ./Modules/_ssl.c: In function ‘_ssl_configure_hostname’:
    ./Modules/_ssl.c:861: error: implicit declaration of function ‘SSL_get0_param’
    ./Modules/_ssl.c:861: warning: initialization makes pointer from integer without a cast
    ./Modules/_ssl.c:863: error: implicit declaration of function ‘X509_VERIFY_PARAM_set1_host’
    ./Modules/_ssl.c:869: error: implicit declaration of function ‘X509_VERIFY_PARAM_set1_ip’
    ./Modules/_ssl.c: In function ‘_ssl__SSLContext_impl’:
    ./Modules/_ssl.c:2988: error: ‘X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS’ undeclared (first use in this function)
    ./Modules/_ssl.c:2988: error: (Each undeclared identifier is reported only once
    ./Modules/_ssl.c:2988: error: for each function it appears in.)
    ./Modules/_ssl.c:3093: error: implicit declaration of function ‘SSL_CTX_get0_param’
    ./Modules/_ssl.c:3093: warning: assignment makes pointer from integer without a cast
    ./Modules/_ssl.c:3099: error: implicit declaration of function ‘X509_VERIFY_PARAM_set_hostflags’
    ./Modules/_ssl.c: In function ‘get_verify_flags’:
    ./Modules/_ssl.c:3397: warning: assignment makes pointer from integer without a cast
    ./Modules/_ssl.c: In function ‘set_verify_flags’:
    ./Modules/_ssl.c:3410: warning: assignment makes pointer from integer without a cast
    ./Modules/_ssl.c: In function ‘set_host_flags’:
    ./Modules/_ssl.c:3573: warning: assignment makes pointer from integer without a cast
    make: *** [Modules/_ssl.o] Error 1`

https://www.tomordonez.com/pip-install-ssl-module-python-is-not-available.html

python centos
10个回答
30
投票

这对我来说适用于基于 Python 3.10.9 的 CentOS 7.9 https://bugs.python.org/issue47201

此编辑

configure
而不是
Modules/Setup

sudo yum install -y epel
sudo yum install -y openssl11-devel
wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
tar zxvf Python-3.10.9.tgz
cd Python-3.10.9
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations
sudo make altinstall
# The following should run without errors if SSL was properly compiled
python3.10 -m ssl

如果更新版本的 Python 适合您,那么对其他人发表评论可能会有所帮助。


17
投票

这是 Python 3.7.9 和 CentOS 7.8.2003 的工作解决方案:

su - root
yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel -y
cd /usr/src
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
tar xzf Python-3.7.9.tgz
cd Python-3.7.9

/usr/src/Python-3.7.9/Modules/Setup.dist
中,取消注释这 4 行:

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

最后:

./configure --enable-optimizations
make altinstall

11
投票

我在openssl版本不兼容时看到过这个错误。当您在不是最新版本的 Linux 系统上安装较新的 Python(例如 3.7.2)时,这种情况更有可能发生。

我会检查此版本的 Python 需要什么版本的 SSL 库,如有必要,请在本地安装它们。

这是构建 SSL 库的基本描述:DreamHost 安装本地 OpenSSL 版本的说明

您将需要再次构建 Python,并将以下选项添加到 ./config 的调用中:

--with-openssl=/path/to/your/local/install

4
投票

对 Kevin Lemaire 之前的答案进行小修正

这是 Python 3.7.9 和 CentOS 7.8.2003 的工作解决方案:

su - root
yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel -y
cd /usr/src
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
tar xzf Python-3.7.9.tgz
cd Python-3.7.9

在模块/设置中,取消注释这 4 行:<<< minor correction

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

最后:

./configure --enable-optimizations
make altinstall

3
投票

请阅读这篇文章

基本上你需要先安装 openssl 并在 python 源代码中的 Modules/Setup 文件中取消注释 ssl 相关行,然后再进行安装。 这对我安装 Python 3.8 很有用。


3
投票

我通过马特的回答解决了问题。

对于那些找不到 epel 包的人:

$ yum install -y epel
......
No package epel available.

$ yum search epel
......
================================ N/S matched: epel ================================
epel-release.noarch : Extra Packages for Enterprise Linux repository configuration

$ yum install epel-release.noarch

1
投票

对我来说,在 CentOS 7.9 上有效并使用以下指南:https://bugs.python.org/issue47201

基本上在下载 Python 3.11.3 并解压它之后,我从它的文件夹中运行:

sudo yum install -y epel
sudo yum install -y openssl11-devel
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure

然后我就跑了:

./configure --enable-optimizations
make altinstall

这成功安装了 python3.11 和 pip3.11,并正确配置了 ssl,并且不再显示错误。


0
投票

我知道这不是 centOS 的答案,但对于像我这样在其他地方找不到答案的其他可怜的人来说,接受的答案可以在 ubuntu 安装上进行以下修改:

sudo apt install libssl-dev liblzo2-dev libpam0g-dev
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations
sudo make altinstall

就我而言,我安装了 python3.7 并且遇到了与此票证中报告的相同的错误。

最后想补充一点,这些步骤将修复您现有的(替代)安装。你不需要(根据我读到的内容,你也不应该)清理 python 安装,除非你真的知道你在做什么。

干杯


-1
投票

从该线程的两个答案中汲取灵感,下载并提取 OpenSSL 1.1.1o,然后运行以下命令序列解决了我的问题。

su - root
yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel -y
cd /usr/src
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
tar xzf Python-3.7.9.tgz
cd Python-3.7.9
./configure --enable-optimizations --with-openssl=/path/to/your/local/install
make install

-7
投票

解决方案:Python 3.6.2 而不是 3.7.1

© www.soinside.com 2019 - 2024. All rights reserved.