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

Eri*_*ric 30 python centos

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

\n\n

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

\n\n

openssl-devel 已安装且是最新的

\n\n

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

\n\n

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

\n\n

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

\n\n
  # Configure the build w/ your installed libraries\n  ./configure\n\n  # Install into /usr/local/bin/python3.6, don\'t overwrite global python bin\n  make altinstall\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n

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

\n\n

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

\n\n

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

\n\n

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

\n\n

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

\n\n
  `uncommented suggestions for CentOs\n  make install failed:\n    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\n    ./Modules/_ssl.c:74:6: error: #error "libssl is too old and does not support X509_VERIFY_PARAM_set1_host()"\n    ./Modules/_ssl.c: In function \xe2\x80\x98_ssl_configure_hostname\xe2\x80\x99:\n    ./Modules/_ssl.c:861: error: implicit declaration of function \xe2\x80\x98SSL_get0_param\xe2\x80\x99\n    ./Modules/_ssl.c:861: warning: initialization makes pointer from integer without a cast\n    ./Modules/_ssl.c:863: error: implicit declaration of function \xe2\x80\x98X509_VERIFY_PARAM_set1_host\xe2\x80\x99\n    ./Modules/_ssl.c:869: error: implicit declaration of function \xe2\x80\x98X509_VERIFY_PARAM_set1_ip\xe2\x80\x99\n    ./Modules/_ssl.c: In function \xe2\x80\x98_ssl__SSLContext_impl\xe2\x80\x99:\n    ./Modules/_ssl.c:2988: error: \xe2\x80\x98X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS\xe2\x80\x99 undeclared (first use in this function)\n    ./Modules/_ssl.c:2988: error: (Each undeclared identifier is reported only once\n    ./Modules/_ssl.c:2988: error: for each function it appears in.)\n    ./Modules/_ssl.c:3093: error: implicit declaration of function \xe2\x80\x98SSL_CTX_get0_param\xe2\x80\x99\n    ./Modules/_ssl.c:3093: warning: assignment makes pointer from integer without a cast\n    ./Modules/_ssl.c:3099: error: implicit declaration of function \xe2\x80\x98X509_VERIFY_PARAM_set_hostflags\xe2\x80\x99\n    ./Modules/_ssl.c: In function \xe2\x80\x98get_verify_flags\xe2\x80\x99:\n    ./Modules/_ssl.c:3397: warning: assignment makes pointer from integer without a cast\n    ./Modules/_ssl.c: In function \xe2\x80\x98set_verify_flags\xe2\x80\x99:\n    ./Modules/_ssl.c:3410: warning: assignment makes pointer from integer without a cast\n    ./Modules/_ssl.c: In function \xe2\x80\x98set_host_flags\xe2\x80\x99:\n    ./Modules/_ssl.c:3573: warning: assignment makes pointer from integer without a cast\n    make: *** [Modules/_ssl.o] Error 1`\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n

Mat*_*att 44

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

此编辑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
Run Code Online (Sandbox Code Playgroud)

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

  • 这适用于 Amazon Linux 2,无需安装“epel”。 (3认同)
  • 这在 Centos7 上运行良好 (2认同)
  • 仅在使用“epel-release.noarch”而不是“epel”后才为我工作 (2认同)

Kev*_*ire 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
Run Code Online (Sandbox Code Playgroud)

在 中/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
Run Code Online (Sandbox Code Playgroud)

最后:

./configure --enable-optimizations
make altinstall
Run Code Online (Sandbox Code Playgroud)

  • 另外,请查看“/usr/src/Python-3.xx/Modules/Setup”以了解其他版本的 Python (3认同)

rho*_*mes 12

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

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

这是构建 SSL 库的基本描述:DreamHost instructions for Installing Local OpenSSL Version

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

--with-openssl=/path/to/your/local/install
Run Code Online (Sandbox Code Playgroud)


Eri*_*ric -7

解决方案:Python 3.6.2 而不是 3.7.1

  • 虽然这可能解决了问题,但我不会称之为解决方案。3.7 的某些功能未包含在 3.6 中。 (5认同)