分类 Python 下的文章

CentOS Python2.4升级到Python2.7

应醒哥要求,挂几个python的程序,结果整了一个下午,本来python是2.4的,好像不支持requests

模块.我就升级到python2.7,结果yum又不能用了.下面是完整的解决方案.

Python升级


# yum install gcc gcc-c++.x86_64 compat-gcc-34-c++.x86_64 openssl-devel.x86_64 zlib*.x86_64
# wget http://www.python.org/ftp/python/2.7/Python-2.7.tar.bz2
# tar -xvjf Python-2.7.tar.bz2
# cd Python*
# ./configure --prefix=/opt/python27
# make
# make install
#vi ~/.bash_profile

replace PATH=$PATH:$HOME/bin
with PATH=$PATH:$HOME/bin:/opt/python27/bin

# source ~/.bash_profile
# echo "/opt/python27/lib" > /etc/ld.so.conf.d/python27.conf
# ldconfig

这时候Python已经升级好了,但是默认的Python版本还是2.4.3

# mv /usr/bin/python /usr/bin/python_backup
# ln -s /opt/python27/bin/python /usr/bin/
# python -V
Python 2.7
这个时候yum又不能用了
# vim /usr/bin/yum
#!/usr/bin/python
改成
#!/usr/bin/python2.4

这时候yum修复了,下面就是安装easy_install,pip和requests

# curl -O http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
# chmod 775 setuptools-0.6c11-py2.7.egg
# sh setuptools-0.6c11-py2.7.egg
# curl -O http://pypi.python.org/packages/source/p/pip/pip-1.0.tar.gz
# tar xvfz pip-1.0.tar.gz
# cd pip-1.0
# python setup.py install
# /opt/python27/bin/easy_install requests

Python Tab 补齐

# easy_install readline
# vim ~/.pythonstartup

[code]
# python startup file
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
[/code]

# echo "export PYTHONSTARTUP=~/.pythonstartup" >> ~/.bashrc