python2.6版本有很多侷限性:最重要的就是,當前最新的pip版本已經不再支持python2.6;這給我們安裝很多python庫增加了很多不便;所以這裏把我升級python2.6--2.7的過程及遇到的坑 記錄一下:
實驗系統版本centos6+ ;centos7+版本自帶的python版本就是2.7+的。
第一步:安裝相關的編譯依賴包:
[root@lexsaints ~]# yum install -y gcc
[root@lexsaints ~]# yum install openssl-devel zlib-devel readline-devel sqlite-devel -y
第二步:到自己的目錄下:下載 解壓 編譯配置
[root@lexsaints ~]# cd /opt/python/
[root@lexsaints ~]# wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
[root@lexsaints ~]# tar -vxf Python-2.7.10.tar
[root@lexsaints ~]# cd Python-2.7.10
[root@lexsaints Python-2.7.10]# ./configure --enable-shared --enable-loadable-sqlite-extensions \ --prefix=/usr/local/python27 --with-zlib --with-ssl
[root@lexsaints Python-2.7.10]# vim ./Modules/Setup
# 打開這句註釋#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
第三步:執行編譯安裝
[root@lexsaints Python-2.7.10]#make && make install
出現的問題:安裝過程中:出現編譯問題:一般都是本機的編譯器gcc等沒有安裝導致的;執行第一步的依賴包安裝;再進行編譯安裝就不會有問題了
第四步:python相關配置
此時安裝完成之後:我們查看版本還是2.6,需要修改配置,用 python2.7 替換舊版本
[root@lexsaints Python-2.7.10]# cd /usr/bin/
[root@lexsaints 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
[root@lexsaints bin]# mv /usr/bin/python /usr/bin/python2.6.6
[root@lexsaints bin]# ln -s /usr/local/python27/bin/python2.7 /usr/bin/python
第五步:配置及yum出現問題的解決
[root@lexsaints ~]# vim /etc/ld.so.conf
# 添加如下一行內容/usr/local/python27/lib
[root@lexsaints ~]# ldconfig # 使新添加的路徑生效
然後 就可以了:python -V :2.7.10
另外:安裝完之後:由於現有的yum需要依賴python2.6;而我們配置了python2.7之後;yum會自動使用2.7所以造成yum不可用的問題:
解決方法:編輯 yum 配置文件
[root@lexsaints bin]# vim /usr/bin/yum#!/usr/bin/python
# 第一行修改爲 python2.6.6#!/usr/bin/python2.6.6
============python2.7升級完成===========
然後使用python -V查看版本
安裝pip
[root@lexsaints~]# wget https://bootstrap.pypa.io/get-pip.py
[root@lexsaints~]# python get-pip.py
設置軟連接
[root@lexsaints~]# ln -s /usr/local/python27/bin/pip2.7 /usr/bin/pip
使用pip安裝python庫
[root@lexsaints~]#pip install requests