python版本升级
背景
在对centos机器升级Python版本从3.6到3.10后,pip安装出现了一些问题
[解决pip is configured with locations that require TLS/SSL问题]
操作
下载
在官方主站找到合适的版本,并下载 https://www.python.org/ftp/python/
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
2、解压
解压
tar -xzvf Python-3.10.6.tgz
进入解压缩后的文件夹
cd Python-3.10.6
3、先在 /usr/local 建一个文件夹 python3 ( 作为python的安装路径,以免覆盖老的版本)
mkdir /usr/local/python3
4、安装相关依赖
yum install gcc libffi-devel zlib* openssl-devel libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y
5、开始编译安装
./configure --with-ssl --prefix=/usr/local/python3
make && make install
配置软连接
删除旧版本的软链接
rm -rf ./python3
rm -rf ./pip3
再建立新版本python的链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
检查版本
python -V
bug: 使用pip 命令失败
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
原因:python之前版本需要的openssl的版本为1.0.2或者1.1.x,需要对openssl进行升级,并重新编译python,yum 安装的openssl 版本都比较低
升级openssl
https://www.openssl.org/source/
1.下载openssl
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz
tar -zxvf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
2.编译安装
./config --prefix=/usr/local/openssl no-zlib #不需要zlib
make && make install
3.备份原配置
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak
4.新版配置
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
5.修改系统配置
写入openssl库文件的搜索路径
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
使修改后的/etc/ld.so.conf
生效
ldconfig -v
6.查看openssl版本
openssl version
最后到Python3.10文件夹下重新编译安装
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make && make install
成功!!!
[root@master Python-3.10.6]# python3 -m pip install --upgrade pip
Requirement already satisfied: pip in /usr/local/python3/lib/python3.10/site-packages (22.2.1)
Collecting pip
Downloading pip-22.2.2-py3-none-any.whl (2.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 406.5 kB/s eta 0:00:00
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.2.1
Uninstalling pip-22.2.1:
Successfully uninstalled pip-22.2.1
WARNING: The scripts pip, pip3 and pip3.10 are installed in '/usr/local/python3/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.2.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
下面的警告一个是建议不要使用root来运行Pip会弄乱系统的pip包,另一个是建议将python3加入到系统环境变量
echo 'export PATH=/usr/local/python3/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
下面的警告一个是建议不要使用root来运行Pip会弄乱系统的pip包,另一个是建议将python3加入到系统环境变量
echo 'export PATH=/usr/local/python3/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
文章出处登录后可见!