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

來源:互聯網
上載者:User

一、安裝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,還比如我vi了setup.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

 

改為:(去掉注釋符,指定它的include和lib的位置)

 

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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.