修改Centos7默认Python版本

1.更新yum

yum update

2.安装Python 3.7.3所需的依赖

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make

3.下载安装包解压

cd /usr/src
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar -zxvf Python-3.7.3.tgz

4.编译安装

cd Python-3.7.3/
./configure --enable-optimizations
make altinstall

可能出现报错:

“ModuleNotFound:No module named '_ctypes'”

执行以下命令重新编译安装

yum install libffi-devel

5.创建软连接

mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python3.7 /usr/bin/python
mv /usr/bin/pip /usr/bin/pip.bak
ln -s /usr/local/bin/pip3.7 /usr/bin/pip

6.查看是否安装成功

[root@localhost bin]# python -V
Python 3.7.3
[root@localhost bin]# pip -V
pip 19.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

7.修改完python的默认版本后,会存在一个问题,无法执行yum命令,修改yum命令文件,将头文件改为python2.7

vi /usr/libexec/urlgrabber-ext-down
vim /usr/bin/yum
#!/usr/bin/python2.7 #将头文件改为python2.7

 

你可能感兴趣的:(运维)