python3-10.png

一. 卸载老版本Python

yum remove python3*

二. 升级OpenSSL

OpenSSL官网下载页面

因为 Python3.10 要求 OpenSSL 1.1.x版本 , 而 Centos7 自带的版本为 OpenSSL 1.0.2k-fips 26 Jan 2017 , 所以必须升级 OpenSSL , 否则将无法使用 pip 安装模块. 详情查看

  1. 下载OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
  1. 解压
tar -zxvf openssl-1.1.1l.tar.gz
  1. 进入解压好的目录
cd openssl-1.1.1l
  1. 编译安装
./config --prefix=/usr/local/openssl
make -j2 && make install
  1. 替换当前系统的OpenSSL为新版
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old

ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

# 建立动态链接库
ldconfig -v
  1. 查看OpenSSL版本
openssl version

三. 升级Python

Python3.10 官网下载页面

  1. 下载Python3.10压缩包
wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz
  1. 解压
tar xvf Python-3.10.0.tar.xz
  1. 进入Python解压目录
cd Python-3.10.0
  1. 编译安装
./configure -prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
  1. 创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
  1. 查看 Pythonpip 版本
python3 -V
Python 3.10.0

pip3 -V
pip 21.3.1 from /usr/local/python3/lib/python3.10/site-packages/pip (python 3.10)
  1. 使用 pip 安装测试, 是否可用
pip3 install flask

Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting flask
  Downloading https://mirrors.aliyun.com/pypi/packages/8f/b6/b4fdcb6d01ee20f9cfe81dcf9d3cd6c2f874b996f186f1c0b898c4a59c04/Flask-2.0.2-py3-none-any.whl (95 kB)
     |████████████████████████████████| 95 kB 5.0 MB/s           
Requirement already satisfied: click>=7.1.2 in /usr/local/python3/lib/python3.10/site-packages (from flask) (8.0.3)
Collecting Jinja2>=3.0
  Downloading https://mirrors.aliyun.com/pypi/packages/20/9a/e5d9ec41927401e41aea8af6d16e78b5e612bca4699d417f646a9610a076/Jinja2-3.0.3-py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 18.4 MB/s          
Collecting Werkzeug>=2.0
  Downloading https://mirrors.aliyun.com/pypi/packages/1e/73/51137805d1b8d97367a8a77cae4a792af14bb7ce58fbd071af294c740cf0/Werkzeug-2.0.2-py3-none-any.whl (288 kB)
     |████████████████████████████████| 288 kB 94.7 MB/s          
Collecting itsdangerous>=2.0
  Downloading https://mirrors.aliyun.com/pypi/packages/9c/96/26f935afba9cd6140216da5add223a0c465b99d0f112b68a4ca426441019/itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting MarkupSafe>=2.0
  Downloading https://mirrors.aliyun.com/pypi/packages/53/e8/601efa63c4058311a8bda7984a2fe554b9da574044967d7aee253661ee46/MarkupSafe-2.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Installing collected packages: MarkupSafe, Werkzeug, Jinja2, itsdangerous, flask
Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.2 flask-2.0.2 itsdangerous-2.0.1

OK

Last modification:November 15th, 2021 at 06:09 pm
如果觉得我的文章对你有用,请随意赞赏