系统:centos6.8

如果后续还需要安装easy_install和pip,为了避免报错(报错内容参考另一篇文章:安装setuptools和pip 以及安装时报错解决http://ganmu.blog.51cto.com/9305511/1954963),需要在安装python前安装下列包:

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline

方法一:

1、安装python2.7.6

cd ~mkdir pythoncd python/wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgztar xf Python-2.7.6.tgzcd Python-2.7.6./configure --helpyum install -y readline-devel./configure --prefix=/usr/local/python27make && make install

    其中  yum install -y readline-devel  是为了更好的支持交互模式,如回退 (具体不安装有没有影响,暂时还没有尝试)

2、安装ipython1.2.1

    python默认不带命令补全功能,ipython具有命令补全等功能,为了方便可以进行安装。

cd ~/pythonwget https://pypi.python.org/packages/42/a0/204ecd8b4e76f3399b51addbd39980ec5fa90275ff853879e25508030922/ipython-1.2.1.tar.gz#md5=4ffb36697f7ca8cb4a2de0f5b30bc89ctar xf ipython-1.2.1.tar.gzcd ipython-1.2.1ls/usr/local/python27/bin/python2.7 setup.py --help/usr/local/python27/bin/python2.7 setup.py build/usr/local/python27/bin/python2.7 setup.py installls /usr/local/python27/bin/ipython

3、链接文件到系统变量路径

     将python2.7和ipython都链接到/usr/bin路径下,以便系统能够通过环境变量直接查找到这两个命令。

ln -sv /usr/local/python27/bin/ipython /usr/bin/ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27ipython

python下载地址 

ipython-1.2.1 下载地址  

 

ipython使用pip安装 pip install ipython  参考地址 

 

方法二:

1、安装python2.7.6

yum groupinstall -y "开发工具" #或者   yum groupinstall -y "Development tools"mkdir softcd soft/wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xztar xf Python-2.7.6.tar.xzcd Python-2.7.6./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"make && make altinstall

2、安装python3.3.5

cd ~/soft/wget http://python.org/ftp/python/3.3.5/Python-3.3.5.tar.xzxz -d Python-3.3.5.tar.xztar xf Python-3.3.5.tarcd Python-3.3.5./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"make && make altinstall

3、安装完python2或者python3后

echo "/usr/local/lib" >> /etc/ld.so.conf/sbin/ldconfigpython2.7 或python3.3

参考:   (其中ez_setup.py已淘汰)