Table of contents
Check the current python version
Download the installation package
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
- CentOS7 defaults to python2.7-----soft links correspond to python and python2.7
- 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
- Delete the python soft connection first
- 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