CentOS 6 预装的python版本是2.6,由于python2.6不支持ipython等一系列库,所以需要安装python2.7,python3如果有需要安装方法应该类似。
安装python2.7不建议直接覆盖python2.6,因为yum本身是需要Python2.6的支持,有见过直接覆盖后yum就失效的情况。因此使用python2.7我们采用virtualenv的方法,不会影响原生的2.6版本。
安装参考 CENTOS 6.5 安装 Python 2.7 总结,总共分为3部分:
1.安装python2.7
2.安装2.7对应的easy_install 和 pip
3.安装virtualenv
安装过程中会需要用到zlib和openssl,需要在安装python2.7前就安装好。因此步骤大致如下:
预安装:
yum install zlib-devel
yum install openssl-devel
1.
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar xf Python-2.7.8.tgz
cd Python-2.7.8
./configure –prefix=/usr/local
make && make install
2.
# First get the setup script for Setuptools:
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# Then install it for Python 2.7 :
python2.7 ez_setup.py
# Now install pip using the newly installed setuptools:
easy_install-2.7 pip
3.
# Install virtualenv for Python 2.7 and create a sandbox called my27project:
pip2.7 install virtualenv
virtualenv-2.7 my27project
# Check the system Python interpreter version:
python –version
# This will show Python 2.6.6
# Activate the my27project sandbox and check the version of the default Python interpreter in it:
source my27project/bin/activate
python –version
# This will show Python 2.7.X
之后每次使用python2.7只需要source一下active文件就可以了
参考: