Centos 6.* 升级python到2.7.*
1,为什么要升级?
Python2.7.*是目前python目前使用最多,长期支持的版本。有关python2.7的改进的详细信息,参阅:http://docs.python.org/dev/whatsnew/2.7.html。其中的参数解析模块argparse可以更加方便地进行参数解;subprocess中的check_output()可以让我们更加方便检查子进程的输出;unittest更方便的进行单元测试;collections中的有序字典和Counter提供了强大的数据结构支持;Memoryview可以查看内存;str.format()可以自动分配序号等。
Cenos 6.*默认安装的是python2.6.*,不支持上述功能,为此我们需要把python升级到2.7.*。
2, 升级步骤:
1) 下载nux的release文件:
# wgethttp://li.nux.ro/download/nux/dextop/el6/i386/nux-dextop-release-0-2.el6.nux.noarch.rpm
2) 安装nux 的release文件:
# rpm -ivh nux-dextop-release-0-2.el6.nux.noarch.rpm
warning: nux-dextop-release-0-2.el6.nux.noarch.rpm:Header V4 RSA/SHA1 Signature, key ID 85c6cd8a: NOKEY
Preparing... ########################################### [100%]
1:nux-dextop-release ########################################### [100%]
3) 安装python 2.7:
# yum -y install python27
# yum -y install python27-devel
Centos默认还是使用python2.6.*,需要用python2.7的文件覆盖python文件。
# cd /usr/bin
# rm -f python
#cp python2.7 python
#python
Python 2.7.3(default, Jan 5 2013, 11:24:11)
[GCC 4.4.620120305 (Red Hat 4.4.6-4)] on linux2
Type"help", "copyright", "credits" or"license" for more information.
>>>quit()
如果看到python 2.7.* 的字样,表示python已经升级成功。
由于yum没有兼容python2.7,需要将下面红色的部分由#!/usr/bin/python 修改为 #!/usr/bin/python2.6。
# vi /usr/bin/yum
#!/usr/bin/python2.6
import sys
try:
import yum
exceptImportError:
print >> sys.stderr,"""\
There was aproblem importing one of the Python modules
required torun yum. The error leading to this problem was:
%s
Pleaseinstall a package which provides this module, or
verify thatthe module is installed correctly.
It'spossible that the above module doesn't match the
currentversion of Python, which is:
%s
If youcannot solve this problem yourself, please go to
the yum faqat:
http://yum.baseurl.org/wiki/Faq
"""% (sys.exc_value, sys.version)
sys.exit(1)
sys.path.insert(0,'/usr/share/yum-cli')
try:
import yummain
yummain.user_main(sys.argv[1:],exit_code=True)
exceptKeyboardInterrupt, e:
print >> sys.stderr,"\n\nExiting on user cancel."
sys.exit(1)
6) 安装setuptools:
Setuptools是python的自动安装工具。
# tar xzvf setuptools-0.6c11.tar.gz
# cd setuptools-0.6c11
# python setup.py install
上面的python setup.py install是python源码模块通用的安装方式。但是安装了setuptools之后,可以使用easy_install来安装大多数python模块。比如:
这样就可以安装pip模块。Pip模块安装成功之后,还可以使用pip来安装软件比如安装pexpect模块:
# pip install pexpect
7) 配置ibus:
Ibus默认使用python2.6。
#vi /usr/bin/ibus-setup
#vi/usr/libexec/ibus-ui-gtk
把其中的execpython改成execpython2.6。这样中文输入法就可以正常了。
至此python升级已经完成。
注意:请在安装centos6.* 之后,安装python相关模块(比如robotFramework)之前,执行上述步骤。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)