1. The python version that comes with the server CentOS7 is 2. I am used to python3. The first step is to upgrade the version.
#Python3.7以上的版本,需要多安装一个依赖包
yum install -y libffi-devel
# 下载
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
# 解压
tar -xzf Python-3.9.1.tgz
#然后 cd Python-3.9.1 文件目录下。创建Python-3.9.1的安装目录:
mkdir /usr/local/python3/
# 进入python目录
cd Python-3.9.1
#在Python-3.9.1目录下生成安装配置文件:
./configure --prefix=/usr/local/python3
#然后执行编译和安装:
make && make install
Second, modify the system path and point.
After the installation is complete, the next step is to configure system connections and path pointers.
First remove the old python version of centos:
mv /usr/bin/python /usr/bin/python_old
mv /usr/bin/pip /usr/bin/pip_old
Finally modify the system soft link:
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip
3. Change the yum configuration
Because yum needs to use python2, after changing /usr/bin/python to python3, yum cannot run normally, so you need to change the configuration of yum.
vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python
Edit these two files and change the file header #!/usr/bin/python2
to .
4. Whether the verification is successful
python -V
pip -V
Optional: update pip
pip install --upgrade pip