CentOS編譯安裝perl、python及問題解決

一、安裝perl


[root@centos ~]# wget http://www.cpan.org/src/5.0/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://www.python.org/ftp/python/2.7.3/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正常。

----------------------------------補充-2012-08-26---------------------------------------------

之前因爲/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://www.cnblogs.com/lexus/archive/2012/02/23/2365660.html

Update:上面安裝zlib的方法失敗,原來Python 2.7得先安裝zlib庫:

cd /opt/Python-2.7.2/Modules/zlib
./configure make && make install

如此安裝zlib

二、http://blog.sina.com.cn/s/blog_814b01e70100z6h7.html

這裏,我們很清楚的可以看出,readline模塊build失敗了,我又查看是否build時有相關報錯,我發現build過程有下列不明顯的報錯:

building 'readline' extension

gcc -fPIC -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -I/usr/local/include -I/tmp/Python-2.7.2/Include -I/tmp/Python-2.7.2 -c /tmp/Python-2.7.2/Modules/readline.c -o build/temp.solaris-2.10-sun4u-2.7/tmp/Python-2.7.2/Modules/readline.o

/tmp/Python-2.7.2/Modules/readline.c:758: warning: 'on_completion_display_matches_hook' defined but not used

gcc -shared build/temp.solaris-2.10-sun4u-2.7/tmp/Python-2.7.2/Modules/readline.o -L/usr/lib/termcap -L/usr/local/lib -L. -lreadline -lncurses -lpython2.7 -o build/lib.solaris-2.10-sun4u-2.7/readline.so

Text relocation remains    

 

這個報錯類似於python自己的module下,有它定義好的readline編譯方式,它和我在config時,指定的readline有所衝突,不知道爲什麼,build時沒法使用。雖然我在configure時,爲此增加了很多參數,比如LDFLAGS,比如CPPFLAGS,還比如我visetup.py文件,在# Platform-dependent module source and include directories

裏定義了readline的位置,但是我們仍無法加載readline

 

我和同事查了很多的文檔和資料,最後我們發現有文檔說,我們需要修改某個配置文件,值得python的模塊可以正常調用。

python安裝目錄下,有個名爲Module的目錄,裏邊有個Setup.dist的配置文件,基本需要加載的模塊都可以在裏邊找到。

 

Vi這個文件,我們找到readline,會發現有簡單的說明,並指明如果要定義一個全新的位置,我們可以通過參數修改

# GNU readline.  Unlike previous Python incarnations, GNU readline is

# now incorporated in an optional module, configured in the Setup file

# instead of by a configure script switch.  You may have to insert a

# -L option pointing to the directory where libreadline.* lives,

# and you may have to change -ltermcap to -ltermlib or perhaps remove

# it, depending on your system -- see the GNU readline instructions.

# It's okay for this to be a shared library, too.

 

#readline readline.c -lreadline –ltermcap

 

改爲:(去掉註釋符,指定它的includelib的位置

 

readline readline.c -I/proj/application/tools/readline-5.2-sol/include -L/proj/application/tools/readline-5.2-sol/lib -R/proj/application/tools/readline-5.2-s

ol/lib -lreadline –ltermcap

 

修改後,我們再次從新編譯。

安裝python我們需要sqlite模塊,所以我事先安裝好了,臨時設置一下環境變量

export PATH=/proj/application/tools/sqlite-3.7.2-sol/bin:$PATH

export LD_LIBRARY_PATH=/proj/application/tools/sqlite-3.7.2-sol/lib:$LD_LIBRARY_PATH

 

再次編譯時,我沒有像以前一樣去改pythonsetup.py文件,我們做過多次的測試,只要指定好環境變量,應該很順利。

./configure --prefix=/proj/application/tools/python-2.7.2/ --enable-shared

Make

Makeinstall

 

沒有任何報錯,readline模塊也加載正常。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章