CentOS下Python2.6升级到Python3.5

1、下载python3.5

wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz

注:如果在Linux中下载较慢,可以在Windows操作系统中去Python官网下载:https://www.python.org/downloads/release/python-350/

注意要下载Gzipped source tarball版本的,然后使用WinSCP将下载好的文件Python-3.5.0.tgz拖拽到Linux中,后续步骤还是不变的。

2、解压

tar zxvf Python-3.5.0.tgz

3、进入Python-3.5.0文件夹

cd Python-3.5.0

4、配置安装位置

./configure --prefix=/usr/local/python3.5

注:如果没有安装C语言编译器会提示错误。如果出现错误,在联网的情况下使用 yum install gcc 命令安装gcc编译器

5、编译

make

6、安装

make install

7、下载并安装setuptools 18.5

wget https://bootstrap.pypa.io/ez_setup.py -O - | python

注:如果提示错误 --no-check-certificate 

在wget后加上 --no-check-certificate :wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | python

8、备份原有python命令执行文件

mv /usr/bin/python /usr/bin/pythonbak

9、创建新python软连接

ln -s /usr/local/python3.5/bin/python3.5 /usr/bin/python

10、查看python版本

python

[root@localhost Python-3.5.0]# python
Python 3.5.0 (default, Oct  7 2016, 04:34:35) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
11、修改yum配置文件
vim /usr/bin/yum

#!/usr/bin/python python修改为 python2.6
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   %s

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
%s

If you cannot solve this problem yourself, please go to 
the yum faq at:

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值