Centos 6.* 升级python到2.7.*
2013-10-30 15:30
169 查看
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
4) 升级python:
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已经升级成功。
5) 修改yum:
由于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的自动安装工具。
# wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
# tar xzvf setuptools-0.6c11.tar.gz
# cd setuptools-0.6c11
# python setup.py install
上面的python setup.py install是python源码模块通用的安装方式。但是安装了setuptools之后,可以使用easy_install来安装大多数python模块。比如:
#easy_install pip
这样就可以安装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)之前,执行上述步骤。
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
4) 升级python:
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已经升级成功。
5) 修改yum:
由于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的自动安装工具。
# wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e
# tar xzvf setuptools-0.6c11.tar.gz
# cd setuptools-0.6c11
# python setup.py install
上面的python setup.py install是python源码模块通用的安装方式。但是安装了setuptools之后,可以使用easy_install来安装大多数python模块。比如:
#easy_install pip
这样就可以安装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)之前,执行上述步骤。
相关文章推荐
- CentOS升级Python 2.6到2.7
- centos下python版本升级为2.7.6
- CentOS 6下升级Python版本
- Centos 5.x 升级 python2.7,安装setuptools、mysqldb 完整记录
- centos python2.6升级到python 2.7
- Centos中Python升级为3.X时yum出现except OSError, e: ^ SyntaxError: invalid syntax问题
- CentOS7下 Python2.7.5升级为Python2.7.13
- centos 下PYTHON 升级2.7.3
- centos升级python,以及yum的修复
- Centos 升级到python3后pip 无法使用的解决方法
- Centos 6.4 python 2.6 升级到 2.7
- centos 6.9 升级python 2.6.6 至 3.5.0
- CentOS Python2.4升级到Python2.7
- centos5.6 python2.4.3升级2.7教程
- 完美原创:centos7.1 从源码升级安装Python3.5.2
- 将CentOS系统默认的python手动升级最新到2.7.13版本
- centos5.5_x64 升级Python2.4到2.7
- centos 6.4 python升级到2.7.11
- CentOS7中将PythonY.y.y 升级到PythonX.x.x
- centos 升级 python后 python-setuptools pip 安装依赖报错