CentOS7 installs Python-3.9.2

Table of contents

Check the current python version

Open the /usr/local directory

Download dependencies

Download the installation package

Unzip and install

Add soft connection

View soft link pointing

python oriented python3.9

View soft link pointing

Modify yum configuration

Note: Repoint the python soft connection back to python2.7


Check the current python version

CentOS7 installs python2.7.5 by default. Installing python3 directly will not conflict.

python -v

 

Open the /usr/local directory

Usually when installing software, it is installed in this directory.

cd /usr/local

 

Download dependencies

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

When installing, you will be asked if you agree, just enter y.

 

Download the installation package

wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz

 

Unzip and install

# 解压压缩包 
tar -zxvf Python-3.9.2.tgz 

# 进入文件夹 
cd Python-3.9.2 

# 配置安装位置 
./configure prefix=/usr/local/python3 

# 安装 
make && make install

After successful installation, there will be an additional python3 folder in the /usr/local/ directory.

 

Add soft connection

  1. CentOS7 defaults to python2.7-----soft links correspond to python and python2.7
  2. CentOS7 newly installs python3.9-----the soft link is named python3
ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3 
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip3 python3 -V pip3 -V

 

View soft link pointing

ll /usr/bin/ |grep python

 

python oriented python3.9

  1. Delete the python soft connection first
  2. Then point it to python3 again.
rm -rf /usr/bin/python 
ln -s /usr/bin/python3 /usr/bin/python

 

View soft link pointing

ll /usr/bin/ |grep python

 

Modify yum configuration

Yum must use python2 to execute, otherwise yum will not be able to be used normally.

#! /usr/bin/python 修改为 #! /usr/bin/python2
vi /usr/bin/yum

#! /usr/bin/python 修改为 #! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down

#!/usr/bin/python 改为 #!/usr/bin/python2
vi /usr/bin/yum-config-manager

 

Note: Repoint the python soft connection back to python2.7

rm -rf /usr/bin/python
ln -s /usr/bin/python2.7 /usr/bin/python

 

Guess you like

Origin blog.csdn.net/gnwu1111/article/details/114966129