以centos为例
默认python版本为:
python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
升级py 我们这边用的是较新的版本3.5
一、下载及安装
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
tar -zxvf Python-3.5.2.tgz
cd Python-3.5.2
mkdir /usr/local/python3
./configure --prefix=/usr/local/python3
make && make install
二、重命名老python版本,把新版本软连接到系统环境中
mv /usr/bin/python /usr/bin/python_26
ln -s /usr/local/python3/bin/python3 /usr/bin/python
三、验证
python
Python 3.5.2 (default, Dec 29 2016, 16:34:53)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[root@station88 Python-3.5.2]# cat test.py
import os
print ('hello world')
[root@station88 Python-3.5.2]# python test.py
hello world
[root@station88 Python-3.5.2]#
报错处理:
使用yum报错
解决:
[root@station88 ~]# cp /usr/bin/yum /usr/bin/yum.backup_2016-12-30
vim /usr/bin/yum
#!/usr/bin/python 修改为:/usr/bin/python_2016-12-30
cat /usr/bin/yum |grep /usr/bin/pyth
#!/usr/bin/python2.6