Linux_升級python 2.7.3(centos)

首先下載源tar包
可利用linux自帶下載工具wget下載,如下所示:
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz


下載完成後到下載目錄下,解壓
tar -zxvf Python-2.7.3.tgz

進入解壓縮後的文件夾
cd Python-2.7.3


在編譯前先在/usr/local建一個文件夾python27(作爲python的安裝路徑,以免覆蓋老的版本)
mkdir /usr/local/python2.7.3


在解壓縮後的目錄下編譯安裝
./configure --prefix=/usr/local/python2.7.3
make
make install


此時沒有覆蓋老版本,再將原來/usr/bin/python鏈接改爲別的名字
mv /usr/bin/python /usr/bin/python_old(這裏僅僅是改名,將老版本的/usr/bin/python改名爲/usr/bin/python_old,如果是python2.6,就改爲usr/bin/python_2.6)


再建立新版本python的鏈接
ln -s /usr/local/python2.7.3/bin/python2.7   /usr/bin/python


這個時候輸入
python
就會顯示出python的新版本信息


#python安裝完畢後,提示找不到ssl模塊:

[root@localhost ~]# python2.7.5 
Python 2.7.5 (default, Jun 3 2013, 11:08:43) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python27/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>

2. 查看openssl安裝包,發現缺少openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5

3. yum安裝openssl-devel
[root@localhost ~]# yum install openssl-devel -y
#查看安裝結果
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-26.el5_9.1
openssl-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1

4. 重新編譯python
#修改Setup文件
vim    /usr/software/Python-2.7.5/Modules/Setup
#修改結果如下:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto


5. 重新編譯安裝python
cd Python-2.7.3

./configure --prefix=/usr/local/python2.7.3

make

make install

6. 測試,已可正常使用。
[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 14:56:13) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>


轉載自:

http://www.jb51.net/article/51800.htm

http://www.cnblogs.com/yuechaotian/archive/2013/06/03/3115472.html

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