第一步:下載python2.7.9版本源碼:
wget http://python.org/ftp/python/2.7.9/Python-2.7.9.tgz
解壓文件
#tar zxvf Python-2.7.9.tar.bz2 root@iZ25xo8uaamZ:/opt/software# cd Python-2.7.9/ root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# dir config.guess Doc LICENSE Objects Python config.sub Grammar Mac Parser README configure Include Makefile.pre.in PC RISCOS configure.ac install-sh Misc PCbuild setup.py Demo Lib Modules pyconfig.h.in Tools root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# mkdir /usr/local/python2.7.9
編譯之前,需要先安裝zlib包:
從官網http://www.zlib.net/下載zlib-1.2.8.tar.gz
root@iZ25xo8uaamZ:/opt/software# tar -xvf zlib-1.2.8.tar.gz root@iZ25xo8uaamZ:/opt/software# cd zlib-1.2.8 root@iZ25xo8uaamZ:/opt/software# ./configure && make && make install
進入Python-2.7.9目錄,開始安裝Python
root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# ./configure --prefix=/usr/local/python2.7.9 root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# make && make install
安裝成功!
root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# python -V Python 2.6.6
版本依然是2.6.6,現在開始升級python,
查看python命令所在目錄
root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# whereis python python: /usr/bin/python2.6 /usr/bin/python /etc/python2.6 /etc/python /usr/lib/python2.6 /usr/lib/python2.4 /usr/lib/python2.5 /usr/local/lib/python2.6 /usr/include/python2.6 /usr/share/python /usr/share/man/man1/python.1.gz
將/usr/bin/python備份
root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# mv /usr/bin/python /usr/bin/python2.6.6
root@iZ25xo8uaamZ:/opt/software/Python-2.7.9# python -bash: /usr/bin/python: No such file or directory
python命令找不到,這時只需要將版本python2.7.9命令加入環境變量即可!
方式1:
修改/etc/profile加入如下兩行:
PATH=$PATH:/usr/local/python2.7.9/bin export PATH
然后
[root@localhost Python-2.7.9]# source /etc/profile [root@localhost Python-2.7.9]# python -V Python 2.7.9
當然也可以創建2.7.9版本的python的軟連接:/usr/bin/python
[root@localhost ~]# ln -s /usr/local/python2.7.9/bin/python2.7 /usr/bin/python
亦可
ok,python升級完成
但運行python get-pip.py時,報錯,原因是 python沒有完全安裝好,缺少ssl模塊
修改 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
重新編譯
make && make install
又報錯:ssl錯誤,原因是openssl-devel未安裝
使用:
apt-get install openssl apt-get install libdev-ssl
再次編譯,搞定
第二步、安裝pip 參見https://pip.pypa.io/en/latest/installing.html
To install pip, securely download get-pip.py. [2]
Then run the following (which may require administrator access):
python get-pip.py
pip被默認安裝在:/usr/local/python2.7.9/bin/
此時要注意pip版本的問題,之前的/usr/bin/pip可能是使用 apt-get install python-pip安裝上的,
將/usr/bin/pip 升級為/usr/local/python2.7.9/bin/pip2.7:
ln -s /usr/local/python2.7.9/bin/pip2.7 /usr/bin/pip
Ok,至此 pip安裝環境構建成功!
第三步、安裝python Django運行必須包 [可選]
1、安裝MySQLdb
官網下載MySQL-python-1.2.3.tar.gz,解壓安裝
# python setup.py install
2、安裝pillow
#pip install pillow
3、安裝uwsgi [可選]
#pip install uwsgi
建立軟鏈接:
# ln -s /usr/local/python2.7.9/bin/uwsgi /usr/bin/uwsgi