加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python升级最新2.7.x的简单示例

发布时间:2020-12-17 07:13:20 所属栏目:Python 来源:网络整理
导读:对python这个高级语言感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧! python2.7是2.X的最后一个版本,同时她也加入了一部分3.X的新特性。并且具有更好的性能,修改多个bug。所以决定升级到最新的2.7版,我的目前的版本是2.4.3 查看当前
对python这个高级语言感兴趣的小伙伴,下面一起跟随编程之家 52php.cn的小编两巴掌来看看吧!

python2.7是2.X的最后一个版本,同时她也加入了一部分3.X的新特性。并且具有更好的性能,修改多个bug。所以决定升级到最新的2.7版,我的目前的版本是2.4.3

查看当前python版本


[root@52php.cn ~]# python
Python 2.4.3 (#1,Sep  3 2009,15:37:37) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help","copyright","credits" or "license" for more information.
>>>

# End www.52php.cn

1.最新版本python下载安装

下载新版本的python


[root@52php.cn ~]# wget http://python.org/ftp/python/2.7.8/Python-2.7.8.tgz

# End www.52php.cn

解压缩 以及编译


[root@52php.cn ~]# tar xvf Python-2.7.8.tar.bz2 
[root@52php.cn Python-2.7.8]# ./configure --prefix=/usr/local/python27
[root@52php.cn Python-2.7.8]# make
[root@52php.cn Python-2.7.8]# make install

# End www.52php.cn

最新2.7.8版本的python已经安装到了系统中,但是还没有完成

再次查看python版本,发现依然是2.4.3版本


[root@52php.cn ~]# python
Python 2.4.3 (#1,"credits" or "license" for more information.
>>>

# End www.52php.cn

2. python多版本共存解决

下面我们来解决这个问题

把原来的python重命名成python_old,注意不要删除它,还有用,下面会说到


[root@52php.cn Python-2.7.8]# mv /usr/bin/python /usr/bin/python_old

# End www.52php.cn

建立新的python的软链接


[root@52php.cn Python-2.7.8]# ln -s /usr/local/python27/bin/python /usr/bin/

# End www.52php.cn

这时候我们再查看一下版本,发现正常啦!


[root@52php.cn Python-2.7.8]# python
Python 2.7.8 (default,Dec  3 2014,10:51:34) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
Type "help","credits" or "license" for more information.
>>>

# End www.52php.cn

至此我们已经可以正常使用python2.7

 

3.解决yum的python版本问题

但是我们还有最后一个问题要解决

但是因为yum是使用的python2.4的版本,所以 还需要修改一下(前面我们重命名的python_old现在派上用场啦)


[root@52php.cn ~]# yum 
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
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:
Python 2.7.8 (default,10:51:34) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)] on linux2
If you cannot solve this problem yourself,please go to 
the yum faq at:
http://wiki.linux.duke.edu/YumFaq

# End www.52php.cn

[root@52php.cn Python-2.7.8]# vim /usr/bin/yum 
#!/usr/bin/python   #修改此处为2.4的位置
[root@52php.cn ~]# vim /usr/bin/yum 
#!/usr/bin/python2.4
[root@52php.cn ~]# yum 
Loaded plugins: fastestmirror
You need to give some command
usage: yum [options] COMMAND
List of Commands:
check-update   Check for available package updates
clean          Remove cached data
deplist        List a package's dependencies
downgrade      downgrade a package
erase          Remove a package or packages from your system
groupinfo      Display details about a package group
groupinstall   Install the packages in a group on your system
grouplist      List available package groups
groupremove    Remove the packages in a group from your system
help           Display a helpful usage message
info           Display details about a package or group of packages
install        Install a package or packages on your system
list           List a package or groups of packages
localinstall   Install a local RPM

# End www.52php.cn

yum 又可以使用了

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读