升级为python3.10
yum update
yum install openssl-devel bzip2-devel libffi-devel
yum groupinstall "Development Tools"
wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz
tar -xzf Python-3.10.2.tgz
cd Python-3.10.2
./configure --enable-optimizations
make altinstall
python3.10 -V
设置软连接:
mv /usr/bin/python3 /usr/bin/python3_old
mv /usr/bin/pip3 /usr/bin/pip3_old
ln -s /usr/local/bin/python3.10 /usr/bin/python3
ln -s /usr/local/bin/pip3.10 /usr/bin/pip3
运行命令查看python版本
python3 -V
问题
但是在使用过程中,例如运行python3 a.py
,可能会报错
File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1056, in _new_conn
raise ImportError(
ImportError: Can't connect to HTTPS URL because the SSL module is not available.
解决办法:
sudo yum install -y epel
sudo yum install -y openssl11-devel
cd Python-3.10.2
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations
sudo make altinstall
# 如果正确编译了SSL,下面的代码应该可以正常运行
python3.10 -m ssl