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

时间:2019-06-11 22:24:25

标签: python centos

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

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

openssl-devel已安装且最新

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

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

"SSL module in Python is not available" when installing package with pip3       #允许构建python ssl库       百胜安装openssl-devel       #下载 any python版本的源代码       光盘/ 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

4 个答案:

答案 0 :(得分:3)

这是适用于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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

请阅读this article

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

答案 3 :(得分:0)

解决方案:Python 3.6.2代替3.7.1