centos安装python2.7

一、安装perl


[root@centos ~]# wget http://bcs.duapp.com/xiueli/perl-5.16.0.tar.gz

[root@centos ~]# tar zxvf perl-5.16.0.tar.gz 

[root@centos ~]# cd perl-5.16.0

[root@centos perl-5.16.0]# mkdir -p /usr/local/perl
[root@centos perl-5.16.0]# ls /usr/local/

编译参数使用默认的

[root@centos perl-5.16.0]# ./Configure -des -Dprefix=/usr/local/perl/

[root@centos perl-5.16.0]# make

[root@centos perl-5.16.0]# make test

[root@centos perl-5.16.0]# make install
到此安装结束,测试是否正常安装。

[root@centos ~]# perl -v
This is perl, v5.8.8 built for i386-linux-thread-multi
Copyright 1987-2006, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

 

二、安装python、及问题解决

 

[root@centos ~]# wget http://bcs.duapp.com/xiueli/Python-2.7.3.tar.bz2

[root@centos ~]# tar jxvf Python-2.7.3.tar.bz2 

[root@centos ~]# cd Python-2.7.3

[root@centos perl-5.16.0]# mkdir -p /usr/local/python
[root@centos perl-5.16.0]# ls /usr/local/

[root@centos Python-2.7.3]# ./configure --prefix=/usr/local/python/

[root@centos Python-2.7.3]# make

遇到问题:

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter        
bsddb185           bz2                dbm             
gdbm               readline           sunaudiodev     
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


Failed to build these modules:
_curses            _curses_panel   

由提示,先解决未编译成功模块_curses、_curses_panel   这是由于相关的库文件找不到引起的,安装ncurses可解决,但ncurses是比较常见的,此前应该安装过,系统里不应该没有,也不管了,使用yum安装。

[root@centos Python-2.7.3]# yum install ncurses ncurses-devel

再次make

[root@centos Python-2.7.3]# make

提示:

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _sqlite3           _tkinter        
bsddb185           bz2                dbm             
gdbm               readline           sunaudiodev     
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

由提示可以看出,之前的模块正常编译,但系统任提示缺少相关必须的位。这个问题困扰了我许久,在网上搜索了大量的资料,也没找到较好的解决办法,自己尝试安装一些相关的库,任然出现这个提示。但网上有些文档提到这个问题很常见,可忽略。自己尝试多次后未果,也只得忽略,后来证明没问题,但这也为我后来安装gitosis出错排错带来了麻烦。忽略之后直接安装。

ps:一些必要的模块还是要安装的,如果自己实在解决不了就大胆跳过,以后遇到问题,提示python某个必要的模块没安装再进行解决。

[root@centos Python-2.7.3]# make install

[root@centos Python-2.7.3]# python -V

Python 2.4.3

此时python版本任为2.4,这是因为centos系统中的python版本默认是2.4。替代默认的版本:

[root@centos bin]# mv /usr/bin/python /usr/bin/python2.4           //可能python2.4已经存在

[root@centos bin]# ln -s /usr/local/python/bin/python /usr/bin/python

[root@centos bin]# which python
/usr/bin/python
[root@centos bin]# python -V
Python 2.7.3

升级安装好以后yum会无法使用,因为yum使用的是2.4版本,此时运行yum会有如下提示

[root@centos bin]# yum update
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.3 (default, Aug 12 2012, 20:23:42) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)]


If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://wiki.linux.duke.edu/YumFaq

修改yum的配置文件以便能够识别2.4版本下的python

[root@centos bin]# vi /usr/bin/yum 
将 #!/usr/bin/python    修改为#!/usr/bin/python2.4

再次运行yum正常。

----------------------------------补充----------------------------------------------------------

之前因为/usr/bin/ 已经有python2.4 所以将原本的python重命名为python2.4.1。修改/usr/bin/yum 是也改#!/usr/bin/python2.4  运行yum正常,但每次开机提示:

Traceback (most recent call last): 
  File "/usr/lib/wicd/wicd-daemon.py", line 46, in <module> 
    import dbus 
ImportError: No module named dbus 

后来修改/usr/bin/yum为#!/usr/bin/python2.4.1 开机正常,无该提示。

所以如果/usr/bin/ 已经有python2.4  mv时建议不要覆盖,但diff /usr/bin/python2.4 /usr/bin/python2.4.1无输出,重新修改/usr/bin/yum为#!/usr/bin/python2.4开机仍提示错误,再次留下疑问!

--------------------------------------补充结束----------------------------------------------------

 

转自 http://yinxiulei.cn

posted @ 2013-04-02 13:36  尹修磊  阅读(1388)  评论(0编辑  收藏  举报