centos7 python2.7 upgrade to 3.9

1. 安装依赖关系
 
yum -y install gcc python36-devel bzip2-devel sqlite-devel openssl-devel readline-devel xz-devel xz-devel tk-devel gdbm-devel libffi-devel

2. 下载和安装python包#
cd /usr/local/src
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
tar zxvf Python-3.9.5.tgz
cd Python-3.9.5/
./configure --prefix=/usr/local/python3.9 --with-ssl
make && make install

3. Modify soft links

ln -fs /usr/local/python3.9/bin/python3.9 /usr/bin/python
ln -fs /usr/local/python3.9/bin/python3.9 /usr/bin/python3
ln -fs /usr/local/python3.9/bin/pip3.9 /usr/bin/pip
ln -fs /usr/local/python3.9/bin/pip3.9 /usr/bin/pip3


5. Modify the yum file 
Change the first line to: (The reason is that python3.8 is installed, and the yum that comes with CentOS 7.X uses python2.X , when the system upgrades python to 2.7 or 3.X, a syntax interpretation error occurs)

Files that need to be modified:

/usr/bin/yum
/usr/libexec/urlgrabber-ext-down

Change the first line #!/usr/bin/python to #!/usr/bin/python2

sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2/g' /usr/bin/yum
sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2/g'  /usr/libexec/urlgrabber-ext-down
sed -i 's/\/usr\/bin\/python/\/usr\/bin\/python2/g' /usr/bin/yum-config-manager
6.升级pip

python -m pip install --upgrade pip
 

Guess you like

Origin blog.csdn.net/weixin_37562883/article/details/134714142