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

rdrgkggo  于 2022-11-07  发布在  Python
关注(0)|答案(6)|浏览(310)

在GoDaddy VPS CentOs上安装新的Python 3.7.1 7.尝试pip 3安装虚拟环境或python 3 -m pip安装虚拟环境并获取:
pip配置了需要TLS/SSL的位置,但是Python中的ssl模块不可用。
openssl-devel已安装并且是最新的
这个问题已经问过很多次了,也回答过很多次了,但是我找到的解决方案并没有解决我的问题。谢谢大家!
我在下面的代码中尝试了CentOs和基于Linux的解决方案:
"SSL module in Python is not available" when installing package with pip3 #允许构建Python ssl库yum安装openssl-devel #下载 * 任何 * 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

Trying to install packages with Python 3.7.2 pip causes TSL/SSL errors
"SSL module in Python is not available" when installing package with pip3
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
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 cannot confirm SSL certificate: SSL module is not available
"ssl module in Python is not available"pip cannot confirm SSL certificate: SSL module is not available的数据类型

`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

vd2z7a6w

vd2z7a6w1#

下面是一个适用于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
ifmq2ha2

ifmq2ha22#

我在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
0sgqnhkj

0sgqnhkj3#

请阅读this article
基本上,你需要先安装openssl,然后在python源代码中的Modules/Setup文件中取消注解ssl相关的行,然后再进行安装。

omtl5h9j

omtl5h9j4#

对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

在Modules/Setup(模块/设置)中,取消注解以下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
nbysray5

nbysray55#

从这篇文章的两个答案中获得灵感,下载并解压缩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
ergxz8rk

ergxz8rk6#

解决方案:Python 3.6.2而不是3.7.1

相关问题