如果电脑自带的python2.7 先卸载
1.强制删除已安装python及其关联
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps
2.删除残余文件
whereis python|xargs rm -frv
开始安装pyton3
1.安装编译 以及 相关的工具
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 libffi-devel -y
2.下载安装包解压
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar -xvJf Python-3.7.0.tar.xz
3.编译安装
mkdir /usr/local/python3 #创建编译安装目录
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install
4.创建软连接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
5.验证是否成功
python3 -V
pip3 -V
# 卸载python3
rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps
# 删除残留文件
whereis python3 |xargs rm -frv
#查看现有安装的python
whereis python
原文地址:https://www.cnblogs.com/richerdyoung/p/12396200.html
时间: 2024-11-06 07:43:26