标签:
第一步:下载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
标签:
原文地址:http://www.cnblogs.com/jaxthon/p/4393016.html