一.环境
阿里云centos 8.5 默认自带了python 3.6版本,由于很多插件更新快,需要更高的版本,这里升级到python3.10.5最新稳定版本。
1)查看python3默认版本
[root@iZwz927xptl8kw8zqrmwvcZ ~]# python3
Python 3.6.8 (default, Sep 10 2021, 09:13:53)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
2)查看python3命令目录
[root@iZwz927xptl8kw8zqrmwvcZ ~]# whereis python
python: /usr/bin/python3.6 /usr/bin/python3.6m /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/python.1.gz
3查看pip3安装包命令目录
[root@iZwz927xptl8kw8zqrmwvcZ ~]# whereis pip3
pip3: /usr/bin/pip3 /usr/bin/pip3.6 /usr/share/man/man1/pip3.1.gz
4.查看pip3和python3的软链接指向地址
[root@iZwz927xptl8kw8zqrmwvcZ bin]# pwd
/usr/bin
[root@iZwz927xptl8kw8zqrmwvcZ bin]# file python3
python3: symbolic link to /etc/alternatives/python3
[root@iZwz927xptl8kw8zqrmwvcZ bin]# file pip3
pip3: symbolic link to /etc/alternatives/pip3
不能删除python3.6文件, 否则会导致yum不可用。
二.安装python3.10.5版本
查看所有python版本包:https://www.python.org/ftp/python/
1)下载 3.8.15 上传到tmp目录 下
2)解压
tar -zxvf Python-3.8.15.tgz
3)定位到tmp/Python-3.8.15目录下
/configure --prefix=/usr/local/python3.8
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel xz-devel gcc
./configure --prefix=/usr/local/python3.8
make && make install
4)安装python3.8成功后试试bz2和sqlite3有没有安装好。
[root@iZwz927xptl8kw8zqrmwvcZ python3.8]# pwd
/usr/local/python3.8
[root@iZwz927xptl8kw8zqrmwvcZ python3.8]# cd bin
[root@iZwz927xptl8kw8zqrmwvcZ bin]# ls
2to3 2to3-3.8 idle3 idle3.8 pip3 pip3.8 pydoc3 pydoc3.8 python3 python3.8 python3.8-config python3-config
[root@iZwz927xptl8kw8zqrmwvcZ bin]# ./python3.8
Python 3.8.15 (default, Dec 13 2022, 17:45:01)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
>>> import sqlite3
>>>exit()
5)创建软连接
ln -s /usr/local/python3.8/bin/pip3.8 /usr/bin/pip3
ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python3.8/bin/pip3.8 /usr/local/bin/pip3
注意:移除旧的软连接时,如果提示软连接存在那是python3.6.8的,需要先删除,在创建链链接。
6).检查版本
[root@iZwz927xptl8kw8zqrmwvcZ ~]# python3 -V
Python 3.8.15
[root@iZwz927xptl8kw8zqrmwvcZ ~]# pip3 -V
Python 3.8.15
参考资料: centos7升级安装python3.8版本
问题:升级后,如使用nohup gerapy runserver 0.0.0.0:8000 > nohup.out& 还是默认使用的python3.6.8,可以通过ps -ef|grep gerapy 来查看
需改成:nohup python3 /usr/local/bin/gerapy runserver 0.0.0.0:8000 > nohup.out& 这样才使用的是3.8.15
暂时没有好的方案