Installing newer or multiple version of python on Centos

I stumbled across this situation where I needed to install python  > 2.7 on Centos. Yum breaks if you upgrade the system python as yum relies on python 2.6 . So the only way to not touch the system python but still be able to use later version of python for your needs is to do the alternate install and then use virtual env to use the newer python. Here is how :

First of all , install the Development tools for some pre-requisite development libraries :

yum groupinstall "Development tools"

Now Install additional Dependencies:

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

Now Download and install the version of python that you require, I for example needed the 2.7.6 :

wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

Next, get the setup script for easy setup tool  and install it for newer version of your python :

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py python2.7 ez_setup.py

Next, install pip using the setup tool :

easy_install-2.7 pip

Now install the virtualenv for newer python and create a sandbox call test-python-2.7

pip2.7 install virtualenv virtualenv -p /usr/local/bin/python2.7 test-python-2.7

Next, Activate the new sandbox  and check the python version :

source test-python-2.7/bin/activate python --version

Now you can deactivate the environment when you are done using the alternate python version:

deactivate