前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS下Python2.6升级到Python3

CentOS下Python2.6升级到Python3

作者头像
一朵灼灼华
发布2022-08-05 18:25:15
4280
发布2022-08-05 18:25:15
举报

1、下载python3

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

[plain] view plain copy

  1. [root@localhost Python-3.5.0]# python  
  2. Python 3.5.0 (default, Oct  7 2016, 04:34:35)   
  3. [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux  
  4. Type "help", "copyright", "credits" or "license" for more information.  

11、修改yum配置文件 vim /usr/bin/yum

[plain] view plain copy

  1. #!/usr/bin/python python修改为 python2.6  
  2. import sys  
  3. try:  
  4.     import yum  
  5. except ImportError:  
  6.     print >> sys.stderr, """  
  7. There was a problem importing one of the Python modules  
  8. required to run yum. The error leading to this problem was:  
  9.    %s  
  10. Please install a package which provides this module, or  
  11. verify that the module is installed correctly.  
  12. It's possible that the above module doesn't match the  
  13. current version of Python, which is:  
  14. %s  
  15. If you cannot solve this problem yourself, please go to   
  16. the yum faq at:  
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-09-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档