Python升級版本2.6到2.7

來源:互聯網
上載者:User

標籤:aries   gcc   extension   list   指定   figure   error   this   name   

CentOS 6 系統預設 Python 版本是:2.6.6 平時在使用中遇到很多的庫要求是 2.7.x 版本的庫,比如使用 ConfigParser 庫,在 2.6 版本庫就不支援沒有 value 值的配置項,需要升級到 2.7 以上的庫才行,這次就嘗試升級一下 Python 到 2.7.x 版本,記錄於此。

在centos6.5中安裝了zabbix,但是需要發送警示,需要版本2.7,所以升級。
一、升級 Python 2.7.10 版本

1. 準備安裝包,系統是迷你安裝
yum install vim gcc make wget -y
yum install openssl-devel zlib-devel readline-devel sqlite-devel -y\

下載
cd /usr/local/src
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz

解壓
tar -zxvf Python-2.7.10.tgz
ls
Python-2.7.10  Python-2.7.10.tgz


2. 編譯配置安裝
cd Python-2.7.10
./configure --enable-shared --enable-loadable-sqlite-extensions \
    --prefix=/usr/local/python27 --with-zlib --with-ssl

vim ./Modules/Setup    # 找到下邊這一行內容,去掉注釋
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
make && make install

3 .查看 python 版本資訊
python -V
Python 2.6.6
# 版本依舊是 2.6.6

4. 用 python2.7 替換舊版本
cd /usr/bin/
 ls python* -l   # 舊 python 版本資訊
-rwxr-xr-x. 2 root root 4864 2月  22 2013  python
lrwxrwxrwx. 1 root root    6 10月 22 18:38 python2 -> python
-rwxr-xr-x. 2 root root 4864 2月  22 2013  python2.6

[[email protected] bin]# mv /usr/bin/python /usr/bin/python2.6.6
[[email protected] bin]# ln -s /usr/local/python27/bin/python2.7 /usr/bin/python

[[email protected] bin]# ls python* -l
lrwxrwxrwx. 1 root root   33 10月 23 00:01 python -> /usr/local/python27/bin/python2.7
lrwxrwxrwx. 1 root root    6 10月 22 18:38 python2 -> python
-rwxr-xr-x. 2 root root 4864 2月  22 2013 python2.6
-rwxr-xr-x. 2 root root 4864 2月  22 2013 python2.6.6

5. 重新驗證 Python 版本資訊

[[email protected] bin]# python -V
Python 2.7.10

可以看到,系統識別的 python 版本已經是 python 2.7.10

執行 python -V 遇到的問題:

python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
# 原因:linux系統預設沒有把/usr/local/python27/lib路徑加入動態庫搜尋路徑

 解決:

[[email protected] ~]# vim /etc/ld.so.conf
# 添加如下一行內容
/usr/local/python27/lib
[[email protected] ~]# ldconfig  # 使新添加的路徑生效

二、解決 yum 相容性問題

因為 yum 是不相容 Python 2.7 的,所以 yum 不能正常工作,我們需要指定 yum 的 Python 為 2.6。

1. 升級 python 後 yum 出現的問題

[[email protected] bin]# yum
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
... ... ... ...

2. 編輯 yum 設定檔

[[email protected] bin]# vim /usr/bin/yum
#!/usr/bin/python
# 第一行修改為 python2.6.6
#!/usr/bin/python2.6.6

3. 驗證 yum 問題解決

[[email protected] bin]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
... ... ... ...

 
三、升級 python 後,安裝 pip 工具

1. 下載安裝

[[email protected] ~]# wget https://bootstrap.pypa.io/get-pip.py
[[email protected] ~]# python get-pip.py

2. 設定軟串連

[[email protected] ~]# ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip

四、安裝 ipython

[[email protected] ~]# pip install ipython==1.2.1
[[email protected] ~]# ln -s /usr/local/python27/bin/ipython /usr/bin/ipython

Python升級版本2.6到2.7

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.