Centos下安装Python3.6和Python2共存

写在前面

centos6.8中默认自带的python版本为python2.6,那么这里需要将其改为python3

下载并解压

官方下载地址为 https://www.python.org/downlo... ,这里已3.6.3为例。

# 下载
 wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
# 解压
tar -zxvf Python-3.6.3.tgz
 
cd Python-3.6.3

安装

[root@localhost ~]# ./configure prefix=/usr/local/python3  --enable-optimizations
  
[root@localhost ~]# make && make install

修改python3为默认的python

[root@localhost ~]# which python
/usr/bin/python

[root@localhost ~]# mv /usr/bin/python /usr/bin/python.bak
/usr/bin/python

[root@localhost ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python

python3和python2共存

[root@localhost ~]# python -V
Python 3.6.3
[root@localhost ~]# python2.6 -V
Python 2.6.6

由于yum用的python仍然是2.6,所以这里修改一下

[root@localhost ~]# vim /usr/bin/yum

将第一行改为:

#!/usr/bin/python2.6
原文地址:http://www.tech1024.com/origi...

相关推荐