yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
进入python目录,并下载python3.8.6
cd python3.8.6
wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
$mkdir -p /usr/local/python3
$tar -zxvf Python-3.8.6.tgz
yum install gcc
3.7后的版本还有安装一个依赖包:
yum install libffi-devel -y
$cd Python-3.8.6
$./configure --prefix=/usr/local/python3
make
make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
检查软链接
[root@localhost bin]# cd /usr/bin [root@localhost bin]# ll python* lrwxrwxrwx. 1 root root 7 May 8 2020 python -> python2 lrwxrwxrwx. 1 root root 9 May 8 2020 python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Nov 20 2015 python2.7 lrwxrwxrwx 1 root root 30 Apr 7 14:09 python3 -> /usr/local/python3/bin/python3 |
vim /etc/profile
加上这个
export PATH=$PATH:$HOME/bin:/usr/local/python3/bin
$source /etc/profile
[root@localhost bin]# python2 -V
Python 2.7.5
[root@localhost bin]# python3 -V
Python 3.8.6
[root@localhost bin]# pip3 -V
pip 20.2.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)