CentOS 6.2安装python 2.7
上一篇 / 下一篇 2012-08-22 17:18:21 / 个人分类:Centos
1.查看当前系统中python的版本
[root@zuantianyang-vmlnx ~]# which python
/usr/bin/python
[root@zuantianyang-vmlnx ~]# python --version
Python 2.6.6
2.下载Python 2.7.2
[root@zuantianyang-vmlnx ~]# wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
3.解压Python-2.7.2.tar.bz2
[root@zuantianyang-vmlnx ~]# tar -jxvf Python-2.7.tar.bz2
4.进入刚解压后的文件夹:
[root@zuantianyang-vmlnx ~]#
5.安装:
[root@zuantianyang-vmlnx Python-2.7.2]# ./configure
[root@zuantianyang-vmlnx Python-2.7.2]# make all
[root@zuantianyang-vmlnx Python-2.7.2]# make install
[root@zuantianyang-vmlnx Python-2.7.2]# make clean
[root@zuantianyang-vmlnx Python-2.7.2]#make distclean
默认python被安装到/usr/local/bin/python2.7
[root@zuantianyang-vmlnx Python-2.7.2]#cd /usr/local/bin
[root@zuantianyang-vmlnx bin]# ls -lrt
total 12028
-rwxr-xr-x. 1 root root 18547 Feb 5 13:56
smtpd.py
-rwxr-xr-x. 1 root root 84 Feb 5 13:56 pydoc
-rwxr-xr-x. 1
root root 99 Feb 5 13:56 idle
-rwxr-xr-x. 1 root root 101 Feb 5
13:56 2to3
-rwxr-xr-x. 2 root root 6139442 Feb 5 13:59
python2.7
-rwxr-xr-x. 2 root root 6139442 Feb 5 13:59 python
-rwxr-xr-x.
1 root root 1624 Feb 5 14:01 python2.7-config
lrwxrwxrwx. 1 root
root 16 Feb 5 14:01 python-config -> python2.7-config
6.备份系统中原来的python 2.6.6
[root@zuantianyang-vmlnx ~]# mv /usr/bin/python
/usr/bin/python2.6.6.bak
[root@zuantianyang-vmlnx ~]# ln -s
/usr/local/bin/python2.7 /usr/bin/python
[root@zuantianyang-vmlnx ~]# cd /usr/bin/
[root@zuantianyang-vmlnx bin]#
ls -lrt python
lrwxrwxrwx. 1 root root 9 Feb 5 14:14 python ->
/usr/local/bin/python2.7
CentOS 6.2上Python 2.7安装成功了!
但是yum还有些问题
[root@zuantianyang-vmlnx ~]# yum list
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:
2.7.2 (default, Feb 5
2012, 13:55:54)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)]
If you cannot
solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
[root@zuantianyang-vmlnx ~]# vi /usr/bin/yum
用的是/usr/bin/python Python 2.7.2
要在python2.7下yum工作要升级一大堆的包,还是使用下面的简便方法让yum工作吧。
将#!/usr/bin/python改为#!/usr/bin/python2.6使用原来系统默认的Python,yum可以工作了。
3.2.29
Installed: rpm-4.8.0-19.el6.x86_64 at 2011-12-22 12:15
Built : CentOS BuildSystem <http://bugs.centos.org> at 2011-12-07 21:34
Committed: Panu Matilainen <pmatilai@redhat.com> at 2011-10-04
Installed: yum-3.2.29-22.el6.centos.noarch at 2011-12-22 12:16
Built : CentOS BuildSystem <http://bugs.centos.org> at 2011-12-08 18:18
Committed: Karanbir Singh <kbsingh@centos.org> at 2011-12-07
Installed: yum-plugin-fastestmirror-1.1.30-10.el6.noarch at 2011-12-22 12:15
Built : CentOS BuildSystem <http://bugs.centos.org> at 2011-12-07 21:07
Committed: James Antill <james.antill@redhat.com> at 2011-09-21
----------------------------------------------------------------
今天开机后发现,输入法的状态栏不见了,去系统输入法设置,发现无法加载,查看自己目录下的.xsession-errors文件,发现pygtk和一些模块无法加载,
安装的话要装很多包来升级,干脆link /usr/bin/python2.6到 /usr/bin/python
rm /usr/bin/python
ln -s /usr/bin/python2.6 python
ln -s /usr/local/bin/python2.7 /usr/bin/python2.7
并且把/usr/local/bin/python 备份成 /usr/local/bin/python.bak,因为这个python是2.7的.
使用python2.7的话需要用/usr/bin/python2.7 给python 2.7安装模块的时候也需要制定路径,
等CentOS升级到python 2.7吧!相关阅读:
- python sys 模块 (dj7491916, 2012-7-05)
- python类型转换、数值操作 (dj7491916, 2012-7-05)
- 拳头---python简介 (amazingat, 2012-8-19)
- selenium webdriver测时ssl安全验证。 (dj7491916, 2012-8-22)
- selenium webdriver处理下拉框 (dj7491916, 2012-8-22)
TAG: CentOS Python python centos