linux下更新python的版本

环境:系统原来自带python2.7和3.6

[root@xsource bin]# pwd
/usr/bin
[root@xsource bin]# ls -al | grep python
lrwxrwxrwx.  1 root root           9 Nov  7  2020 python2 -> python2.7
-rwxr-xr-x.  1 root root       21816 Nov  7  2020 python2.7
lrwxrwxrwx   1 root root          25 Jan  3 08:54 python3 -> /usr/libexec/platform-python3.6
lrwxrwxrwx.  1 root root          31 Nov  3  2020 python3.6 -> /usr/libexec/platform-python3.6

因为程序需要python3.11的特性,所以:安装(编译)python3.11

安装编译时的依赖库

yum -y groupinstall "Development tools"
yum install -y ncurses-devel gdbm-devel xz-devel sqlite-devel tk-devel uuid-devel readline-devel bzip2-devel libffi-devel

安装openssl,并确保版本是1.1.1

yum install -y openssl-devel
openssl version  
OpenSSL 1.1.1k  FIPS 25 Mar 2021

下载python3.11

wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz

编译,要花一点时间(altinstall会跳过映射链接,可以减少和别的版本冲突)

tar xvzf Python-3.11.1.tgz
cd Python-3.11.1
./configure --enable-optimizations && make altinstall

配置软链接

[root@xsource bin]# ln -sf /usr/local/bin/python3.11 /usr/bin/python3
[root@xsource bin]# ln -sf /usr/local/bin/pip3.11 /usr/bin/pip3
[root@xsource bin]# ln -sf /usr/local/bin/python3.11 /usr/bin/python
[root@xsource bin]# ln -sf /usr/local/bin/pip3.11 /usr/bin/pip

覆盖pip(如果需要),因为我这个系统,path里的pip用的不是软链接,所以更新软链接并不更新pip

[root@xsource crm]# which pip
/usr/local/bin/pip

用pip3.11覆盖一下pip

[root@xsource bin]# ls -al
-rwxr-xr-x   1 root root      230 Jan  3 09:55 pip
-rwxr-xr-x   1 root root      227 Dec 22 14:12 pip3
-rwxr-xr-x   1 root root      230 Jan  3 08:46 pip3.11
-rwxr-xr-x   1 root root      227 Dec 22 14:12 pip3.6

其它(如果需要):

  1. 重新用pip安装相关库

  1. 用旧的pip3.6卸载uwsgi

  1. 用新的pip安装uwsgi

你可能感兴趣的:(python,python,pip)