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
2、下载Python3.6.8
新建个/usr/local/python3文件夹
mkdir /usr/local/python3
在python3文件夹下下载安装包
(/usr/local/python3 )
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
解压文件
tar -xvf Python-3.6.8.tar.xz
3、安装Python3
创建安装文件的路径
mkdir /usr/local/python3
4、编译(在解压的文件夹下 /usr/local/python3/python3.6.8)
./configure --prefix=/usr/local/python3
5、安装(在解压的文件夹下 /usr/local/python3/python3.6.8)
make
make install # 先make再make install
6、创建新版本的软链接
修改旧版本
mv /usr/bin/python /usr/bin/python_bakmv /usr/bin/pip /usr/bin/pip_bak
创建新的软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/pythonln -s /usr/local/python3/bin/pip3 /usr/bin/pip
检查python的版本
python -V
7、配置成功后,pip3用不了,需要进一步配置
将/usr/local/python3/bin加入PATH
vim ~/.bash_profile
修改后如下:
.bash_profile
#Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
复制代码
保存退出后,执行以下命令,让上一步修改成功
source ~/.bash_profile
完成!
不过,由于yum是py2写的,所以更换完python路径后,yum可能会出现错误
所以要修改配置文件
vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down
把第一行python改为python2
原文地址:https://www.cnblogs.com/klsw/p/11106166.html
时间: 2024-10-03 02:29:29