简述Centos如何Python2与Python3共存
CentOS7 默认安装了python2.7.5
查看一下Python可执行文件的位置( ‘’‘which python’’’),默认路径一般为’’’/usr/bin/’’’
python默认指向2.7
[root@wwW bin]# ll python*
lrwxrwxrwx. 1 root root 30 1月 17 21:59 python -> /usr/local/python2/bin/python2
lrwxrwxrwx. 1 root root 9 1月 8 04:13 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 4月 11 2018 python2.7
lrwxrwxrwx. 1 root root 7 1月 8 04:13 python.bak -> python2
[root@wwW bin]#
备份
mv python python.bak
安装相关依赖包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
然后备份
mv python python.bak
下载python3二进制包
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
解压
tar -xvf Python-3.7.2.tgz
切换进入
cd Python-3.7.2.
编译安装
./configure prefix=/usr/local/python3
make && make install
添加软链到执行目录下/usr/bin
ln -s /usr/local/python3/bin/python3 /usr/bin/python
[root@wwW ~]# python -V
Python 3.7.2
[root@wwW ~]#
[root@wwW ~]# python2 -V
Python 2.7.5
[root@wwW ~]#
将yum切换为python2
vi /usr/bin/yum
把#! /usr/bin/python改成#! /usr/bin/python2.7
vi /usr/libexec/urlgrabber-ext-down
把#! /usr/bin/python改成#! /usr/bin/python2.7