0%

CentOS升级Python3

OPS笔记:centos7系统默认python2升级python3

安装python

1
2
3
4
5
6
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -zxvf Python-3.7.0.tgz
mkdir /usr/local/python3
cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install

设置默认python软连接

1
2
3
4
5
6
7
8
9
rm -rf /usr/bin/python
rm -rf /usr/bin/pip
rm -rf /usr/bin/python3-config

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

测试python是否可用

1
2
3
python2 --version
python3 --version
python --version

yum改为python2

1
2
3
4
vi /usr/bin/yum
将第一行"#!/usr/bin/python" 改为 "#!/usr/bin/python2"。
# vi /usr/libexec/urlgrabber-ext-down
将第一行"#!/usr/bin/python" 改为 "#!/usr/bin/python2"即可。