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 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. 问题就解决了。