准备环境:
yum install gcc make zlib zlib-devel readline-devel patch openssl-devel
gcc make:安装编译器。zlib:用于python egg安装。readline-devel patch:用于readline模块的申明和头文件等,给使用了readline模块的程序提供编译支持(readline是ipython代码自动补完,自动缩进,高亮显示)。openssl-devel:用于easy_install使用,否则会提示unknown url type且补装后还需要重新编译python所以在此全部安装。ncurses:据说还需要此包,但我的环境中本来就有。
下载并解压Python包,需要使用--no-check-certificate参数,否则会报certificate common name:
wget --no-check-certificate http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar xvf Python-2.7.3.tgz
进入对应文件并编译:
cd Python-2.7.3
./configure
make && make install
configure,生成Makefile,为编译做准备。make,编译。make insatll,安装。
替换默认python:
mv /usr/bin/python /usr/bin/pythonOld2.6
ln -s /usr/local/bin/python2.7 /usr/bin/python
查看是否替换成功(2.7版本即替换成功):
python -V
由于yum得使用旧python才能正常运行,所以修改yum文件将其指向旧python:
vim /usr/bin/yum
#!/usr/bin/pythonOld2.6
wget --no-check-certificate https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.egg
下载并解压readline模块,用于 代码自动补完, 自动缩进,高亮显示:
wget --no-check-certificate https://pypi.python.org/packages/source/r/readline/readline-6.2.4.1.tar.gz
tar zxvf readline-6.2.4.1.tar.gz
cd readline-6.2.4.1
安装readline模块(会提示缺少libreadline.a与libhistory.a):
easy_install readline
查找 libreadline.a与libhistory.a:
[root@bogon readline-6.2.4.1]# find / -name libread*
/lib64/libreadline.so.6.0
/lib64/libreadline.so.6
/tmp/readline-6.2.4.1/rl/readline-lib/libreadline.a
/tmp/readline-6.2.4.1/rl/readline-lib/shlib/libreadline.so.6.2
/usr/lib64/libreadline.so
[root@bogon readline-6.2.4.1]# find / -name libhist*
/tmp/readline-6.2.4.1/rl/readline-lib/libhistory.a
/tmp/readline-6.2.4.1/rl/readline-lib/shlib/libhistory.so.6.2
/usr/lib64/libhistory.so
/usr/lib64/libhistory.so.6.0
/usr/lib64/libhistory.so.6
vi setup.py
extra_objects=['/tmp/readline-6.2.4.1/rl/readline-lib/libreadline.a', '/tmp/readline-6.2.4.1/rl/readline-lib/libhistory.a'],
再安装readline模块:
easy_install install ipython
进入ipython
ipython
WARNING: IPython History requires SQLite, your history will not be saved
Python 2.7.3 (default, Jan 9 2015, 15:53:49)
Type "copyright", "credits" or "license" for more information.
IPython 2.3.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: