Switch python version in centos

install dependencies first

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

this pack may not necessary
yum install libffi-devel -y

download & compile

1
2
3
4
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
cd Python-3.7.6
./configure
make&&make install

modify default setting

python3.7 locate in /usr/local/bin in default
we need to change default python2.7 to python3.7

1
2
3
4
# backup
mv /usr/bin/python /usr/bin/python.bak
# soft link
ln -s /usr/local/bin/python3 /usr/bin/python

modify pip

1
2
3
4
# backup
mv /usr/bin/pip /usr/bin/pip.bak
# soft link
ln -s /usr/local/bin/pip3 /usr/bin/pip

modify yum setting

yum not support python3, so we need point to python2 manually.

vi /usr/libexec/urlgrabber-ext-down
20200207174547.jpg

vi /usr/bin/yum
20200207175001.jpg

modify the first line to #! /usr/bin/python2.7

https://blog.csdn.net/u013214212/article/details/81540840