5
               
  • CentOS 7 (strict requirement) CentOS 7(严格要求) 
  • Python 3.11 (strict requirement)Python 3.11(严格要求)

I had to upgrage a software and it requires now Python 3.11.我不得不升级一个软件,它现在需要 Python 3.11。

I followed instructions from Internet (https://linuxstans.com/how-to-install-python-centos/                        ), and now Python 3.11 is installed, but cannot download anything, so all the programs that have something to do with Internet, including PIP, do not work because SSL package is not installed.我按照互联网 (https://linuxstans.com/how-to-install-python-centos/) 上的说明操作,现在 Python 3.11 已经安装,但无法下载任何东西,因此所有与互联网有关的程序,包括 PIP,都无法运行,因为 SSL 软件包没有安装。

The normal way to install a Python-package is to use PIP, which doesn't work because the SSL package I'm going to install is not installed.安装 Python-package 的正常方法是使用 PIP,但这行不通,因为我要安装的 SSL 软件包还没有安装。

I tried all the advices in internet, but they are all outdated and not working any more, because they are either not for the 3.11 version of Python or not for CentOS 7.我尝试了互联网上的所有建议,但它们都已过时,不再起作用,因为它们要么不适用 3.11 版本的 Python,要么不适用 CentOS 7。

The error I'm getting when running the application software:我在运行应用软件时遇到的错误是

ModuleNotFoundError: No module named '_ssl'模块未找到错误:没有名为"_ssl "的模块

When I try to install ssl with pip:当我尝试用 pip 安装 ssl 时:

# pip install --trusted-host pypi.org ssl
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ssl/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ssl/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ssl/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ssl/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/ssl/
Could not fetch URL https://pypi.org/simple/ssl/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/ssl/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement ssl (from versions: none)
ERROR: No matching distribution found for ssl
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
                   

I downloaded GZip files from https://pypi.org/simple/ssl/                        , unpacked them locally and tried to install them from local source, but PIP insists on HTTPS connection ... stupid tool.我从 https://pypi.org/simple/ssl/ 下载了 GZip 文件,在本地解压缩并尝试从本地源安装,但 PIP 坚持要使用 HTTPS 连接......这工具太蠢了。

What to do? 怎么办? 

                                    
Improve this question 改进这一问题                                     
asked Aug 18, 2022 at 17:58                                        2022 年 8 月 18 日 17:58 提问
Paul's user avatar                                    
                               
Paul                                      
26.2k  41 gold badges128 silver badges258 bronze badges                                    
  • stackoverflow.com/a/57609378/7976758                                     don't install that python package. stackoverflow.com/a/56136782/7976758                                     , stackoverflow.com/search?q=%5Bpip%5D+install+ssl 
    – phd                                   
     Aug 18, 2022 at 18:27                                    stackoverflow.com/a/57609378/7976758 不要安装那个 python 软件包。 stackoverflow.com/a/56136782/7976758 , stackoverflow.com/search?q=%5Bpip%5D+install+ssl
  • Did you yum install openssl-devel                                     before compilation? 
    – phd                                   
     Aug 18, 2022 at 18:29                                    在编译之前,您yum install openssl-devel了吗?
  • Try github.com/pyenv/pyenv                                     Or try build-python3.sh                                     script from github.com/noloader/Build-Scripts                                     These programs try to download necessary requirements and compile from sources. 
    – phd                                   
     Aug 18, 2022 at 18:35                                    试试 github.com/pyenv/pyenv 或试试 github.com/noloader/Build-Scripts 中的 build-python3.sh 脚本 这些程序会尝试从源代码中下载必要的需求并进行编译。
  • 1                                
    github.com/pyenv/pyenv#install-additional-python-versionsgithub.com/pyenv/pyenv#install-additional-python-versions                                   
    – phd                                   
     Aug 18, 2022 at 18:40                                
  • 1                                
    Use pyenv                                     or asdf                                     or equivalent to install Python versions (and proper virtualenvs) don't bother with trying to compile things yourself manually. 
    – Patrick Mevzek                                   
     Aug 18, 2022 at 19:59                                    使用 pyenv 或 asdf 或类似的方法安装 Python 版本(和适当的虚拟环境),不要费心去手动编译。
        

3 Answers  3 答案 3 

        
22
                   

How to get PIP and other HTTPS-based Python programs to work after upgrading to Python 3.11:升级到 Python 3.11 后,如何让 PIP 和其他基于 HTTPS 的 Python 程序正常工作:

First of all: you don't necessarily need any magical tools like pyenv                            . May be pyenv would do these steps, but I'd like to understand what is happening. (Ok, I admit that make                             is also a "magic" tool)首先:你不一定需要像 pyenv 这样神奇的工具。也许 pyenv 可以完成这些步骤,但我还是想弄明白到底发生了什么(好吧,我承认 make 也是一个 "神奇 "的工具)。(好吧,我承认 也是一个 "神奇 "的工具)

Briefly describing: during compilation of Python from source code there is an option to inject OpenSSL support directly into it.简述:在从源代码编译 Python 时,有一个直接注入 OpenSSL 支持的选项。

In CentOS 7 Python 2.7.5 is installed by default and couldn't be updated to the later ones using built-in package manager. Python 3.6.8 is the latest version available in the CentOS 7 repos. 3.6 also couldn't be updated to the later ones using the package manager.在 CentOS 7 中,Python 2.7.5 是默认安装的,无法使用内置软件包管理器更新到后续版本。Python 3.6.8 是 CentOS 7 软件仓库中的最新版本。使用软件包管理器也无法将 3.6 更新到后续版本。

So the only possible solution is to compile Python from source code.因此,唯一可能的解决方案是从源代码编译 Python。

  • Update your 

    yum                                

     packages, reboot, install all the packages neccesssary to run OpenSSL and Python.更新yum软件包,重启,安装运行 OpenSSL 和 Python 所需的所有软件包。
  • Download the latest OpenSSL source code, unpack and compile.下载最新的 OpenSSL 源代码,解压缩并编译。
  • Download the latest Python source code, unpack, configure to use the compiled OpenSSL and compile with altinstall parameter. 

    Do not remove previous Python versions! You will have more problems than benefits.                                

     I had to revert virtual machine to the latest snapshot several times, because I destroyed something completely.下载最新的 Python 源代码,解压缩,配置为使用编译后的 OpenSSL,并使用 altinstall 参数进行编译。不要删除以前的 Python 版本!否则问题会比好处更多。我不得不多次将虚拟机恢复到最新快照,因为我彻底毁掉了一些东西。

Update and install yum packages 更新并安装 yum 软件包                         

> yum update
> yum install openssl-devel bzip2-devel libffi-devel
                       

An article suggests also to install some "Development Tools"一篇文章建议还安装一些“开发工具”

> yum groupinstall "Development Tools"
                       

but this step failed for me and I was able to finish the installation without it.但这一步对我来说失败了,我能够在没有它的情况下完成安装。

Download the latest OpenSSL source code, unpack and compile下载最新的OpenSSL源码,解压并编译                       

I've choosen /usr/src                             directory to do the manipulations with source code.我选择了 /usr/src 目录来对源代码进行操作。

Download 下载 

> cd /usr/src
> wget https://ftp.openssl.org/source/openssl-1.1.1q.tar.gz --no-check-certificate
                       

Unpack 打开包装 

> tar -xzvf openssl-1.1.1q.tar.gz
> cd openssl-1.1.1q
                       

Compile 编译 

> ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib no-shared zlib-dynamic
> make
                       

Run tests for the compiled OpenSSL对已编译的 OpenSSL 运行测试

> make test
                       

Install 安装 

> make install
                       

Check that OpenSSL is installed检查是否安装了 OpenSSL

> openssl version
OpenSSL 1.1.1q  5 Jul 2022
> which openssl
/usr/bin/openssl
                       

Download and compile Python 下载并编译Python                         

Download 下载 

> cd /usr/src
> wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0a4.tgz
                       

Unpack 打开包装 

> tar -xzf Python-3.11.0a4.tgz
> cd Python-3.11.0a4
                       

Configure 配置 

> ./configure --enable-optimizations --with-openssl=/usr
                       

It is important that the --with-openssl                             option has the same value as the --prefix                             option when you configured OpenSSL above!!!重要的是,当您在上面配置 OpenSSL 时,--with-openssl 选项与 --prefix 选项具有相同的值!

Compile and install (It's time for a cup of coffee - it takes time)编译并安装(该喝杯咖啡了 - 这需要时间)

> make altinstall
                       

Checking that Python 3.11 is installed:检查Python 3.11是否已安装:

> python3.11 -V
Python 3.11.0a4
                       

If you have set symbolic links, then Python 3.11 should be callable by "python3" and/or "python" aliases如果您设置了符号链接,则 Python 3.11 应该可以通过“python3”和/或“python”别名调用

> python3 -V
Python 3.11.0a4
> python -V
Python 3.11.0a4
                       

Also check that PIP is working and that symlink-aliases for it are there.还要检查 PIP 是否正常工作以及它的符号链接别名是否存在。

Now it's time to check that your Python-based programs are working. Some of them should be installed again by PIP, because they were installed in subdirectories of previous Python versions.现在是时候检查基于 Python 的程序是否正常工作了。其中一些应该通过 PIP 重新安装,因为它们安装在以前的 Python 版本的子目录中。

After doing these manipulations I also got SSL certificates error:完成这些操作后,我还收到 SSL 证书错误:

<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:998)>

After running 运行后 

> pip3 install certifi
                       

the problem is gone. 问题就解决了。 

                                        
Improve this answer                                        
edited Aug 19, 2022 at 14:42                                        
answered Aug 19, 2022 at 10:53                                        
Paul's user avatar                                        
                                   
Paul                                        
26.2k41 gold badges128 silver badges258 bronze badges                                        
  • 1                                    
    This really fixed my issue. It seems from Python3.10 the install requires OpenSSL 1.1.1 (peps.python.org/pep-0644                                        ) 
    – Haran                                       
     Feb 15, 2023 at 7:00                                        这确实解决了我的问题。从Python3.10开始,安装似乎需要OpenSSL 1.1.1 (peps.python.org/pep-0644)
  • @Haran: glad to hear it. I literally suffered through the path to this solution. 
    – Paul                                       
     Feb 16, 2023 at 10:40                                    
  • @Pranay Aryal: Why are you literally repeating my answer? 
    – Paul                                       
     Dec 21, 2023 at 23:15                                    
Add a comment 添加评论 |                     
        
3
                   

Paul's solution didn't fully work for me. I had to manually set:保罗的解决方案对我来说并不完全有效。 我必须手动设置:

python -c "import certifi; print(certifi.where())"
export SSL_CERT_FILE=/path/to/cacert.pem
                       

After this I got it working.之后我就开始工作了。

                                        
Improve this answer                                        
answered Jun 13, 2023 at 3:30                                        
QuinRiva's user avatar                                        
                                   
QuinRiva                                        
7191 gold badge7 silver badges14 bronze badges                                        
  • They are always changing something making things incompatible and answers - obsolete. In which OS did you try?他们总是在改变一些东西,使事情变得不兼容并且答案变得过时。您在哪个操作系统中尝试过?                                       
    – Paul                                       
     Jun 17, 2023 at 16:02                                    
  • CentOS 7.9. It took me 3 days to solveCentOS 7.9。我花了3天时间才解决                                       
    – QuinRiva                                       
     Jun 19, 2023 at 2:16                                     
Add a comment 添加评论                     
        
-1  -1 
                   

If you get an error at the make test                             stage, then it helped me如果您在 make test 阶段遇到错误,那么它对我有帮助

yum install cpan
                       

then  

"cpan -i Text :: Template"
                       

and  

"cpan -f -i Text :: Template"
                   
                                        
Improve this answer                                        
edited May 7, 2023 at 19:05                                        
InSync's user avatar                                        
                                   
InSync                                        
7,7474 gold badges11 silver badges36 bronze badges                                        
answered Mar 21, 2023 at 9:33                                        
alaniel's user avatar                                        
                                   
alaniel                                        
1                                        
  • I edited your answer to remove distractions. If you want to thank someone, upvote their answer (you'll need at least 15 reputations to do this).我编辑了你的答案以消除干扰。如果您想感谢某人,请为他们的答案点赞(您需要至少 15 个声望才能做到这一点)。                                       
    – InSync                                       
     May 7, 2023 at 19:06                                    
Add a comment 添加评论                     
        

Your Answer  您的答案


                       

来自  https://stackoverflow.com/questions/73407527/installing-ssl-package-with-pip-requires-ssl-package-to-be-already-installed