1.下载安装包
下载地址1:https://www.python.org/downloads/release
下载地址2:https://www.python.org/ftp/python
也可以进入服务器用命令下载:
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
2.安装编译工具
安装时报错,需要先安装对应工具包
把需要的工具包一次安装完。root用户登录服务器,执行下面命令
yum -y install wget wge #这个就是上一步报错提示的,缺少这个工具包
yum -y groupinstall "Development tools"
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
yum install -y libffi-devel zlib1g-dev
yum install zlib* -y
https开头的提示缺少协议类型,加一个参数
wget --no-check-certificate https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
3.解压
tar -xvJf Python-3.8.5.tar.xz
# 把刚解压的文件移动到python3文件夹下
mv Python-3.8.5 /usr/local/python3
4.安装
cd /usr/local/python3
./configure -prefix=/usr/local/python3 #指明安装路径
make && make install #编译安装
安装成功
5.创建软链接
根目录下输入python,可能出现的python是2.7,不是python3版本,这是因为默认的软连接是2.7,修改软连接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
6.验证安装
python3 # 输入
pip3 -V #V大写
7.其它修改
问题:安装python3后,执行yum命令报错
解决:因为yum是依赖于Python2的,所以需要将2个文件头部的声明路径改回python2.7即可使用yum
vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down
再次运行命令