centos8(linux):编译升级python版本:从python3.6到python3.11
一,查看python本地版本和最新版本
1,查看本地版本:
[lhdop@blog ~]$ python3 --version Python 3.6.8
2,查看最新版本:
https://www.python.org/downloads/
可以看到最新版本:
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/06/03/centos8-linux-bian-yi-sheng-ji-python-ban-ben-cong-python3/
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,安装python3.11
说明:编译安装前,需要gcc、make 等工具已安装
1,下载:
复制下载链接后,
在本地用wget下载
[lhdop@blog python]$ wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz
2,解压:
[lhdop@blog python]$ tar -zxvf Python-3.11.0.tgz
3,配置:
[lhdop@blog Python-3.11.0]$ ./configure --prefix=/usr/local/soft/python3.11 --enable-optimizations
4,编译:
[lhdop@blog Python-3.11.0]$ make
5,安装:
[lhdop@blog Python-3.11.0]$ make install
6,查看安装的效果:
[lhdop@blog Python-3.11.0]$ /usr/local/soft/python3.11/bin/python3 --version Python 3.11.0 [lhdop@blog Python-3.11.0]$ /usr/local/soft/python3.11/bin/pip3 -V pip 22.3 from /usr/local/soft/python3.11/lib/python3.11/site-packages/pip (python 3.11)
三,替换原有python并查看效果
查看原有的python的路径并替换
[root@blog ~]# whereis python3 python3: /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python3 /usr/bin/python3.6-config /usr/bin/python3.6m-config
/usr/bin/python3.6m-x86_64-config /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/lib/python3.6 /usr/include/python3.6m
/usr/share/man/man1/python3.1.gz [root@blog ~]# mv /usr/bin/python3 /usr/bin/python3.6.bak [root@blog ~]# ln -s /usr/local/soft/python3.11/bin/python3 /usr/bin/python3
查看原有的pip的路径并替换
[root@blog ~]# whereis pip3 pip3: /usr/bin/pip3 /usr/bin/pip3.6 /usr/local/bin/pip3 /usr/local/bin/pip3.6 /usr/share/man/man1/pip3.1.gz [root@blog ~]# mv /usr/bin/pip3 /usr/bin/pip3.bak [root@blog ~]# ln -s /usr/local/soft/python3.11/bin/pip3 /usr/bin/pip3
测试效果:
[root@blog ~]# python3 --version Python 3.11.0 [root@blog ~]# pip3 -V pip 22.3 from /usr/local/soft/python3.11/lib/python3.11/site-packages/pip (python 3.11)
四,查看linux的版本:
[root@blog ~]# cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)