说明:CentOS 7最小化安装,默认Python 2.7 ,开发需要安装python3.9.6 。
1、检查python版本
[root@bogon ~]# python -V
Python 2.7.5
[root@bogon ~]#
2、安装必要的库文件
yum -y install zlib zlib-devel gcc openssl* readline readline-devel libffi-devel sqlite-devel
3、下载python3到/usr/local目录
wget https://oss.meibbc.com/BeautifyBreast/file/images/Python-3.9.6.tar.xz
4、解压安装
xz -d Python-3.9.6.tar.xz
tar -xvf Python-3.9.6.tar
cd Python-3.9.6/
./configure --enable-optimizations --prefix=/usr/local/python3 --with-ssl
make && make install
5、添加环境变量
vim /etc/profile
export PATH="$PATH:/usr/local/python3/bin"
添加完成后
source /etc/profile
6、打开python3.6
[root@bogon ~]# python3
Python 3.9.6 (default, Mar 31 2022, 02:22:57)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
7、修改/usr/bin/python链接
cd /usr/bin
mv python python.bak
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
修改后可直接用 # python打开python3