How to Upgrade Python in CentOS
This guide will teach you how to upgrade from Python 2.4 to Python 2.7.
First you need to check your current Python Version:
python -V
If it returns 2.4 then execute the following steps:
wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar -zxvf Python-2.7.3.tgz
cd Python-2.7.3
yum install gcc
./configure –enable-shared
make
make altinstall
The above method will install Python 2.7 without overwriting the original 2.4 version of Python in CentOS (NOTE: Overwriting 2.4 completely with 2.7 is bad!)
Basically the “make altinstall” will install Python 2.7 to “/usr/local/bin/python2.7″
To check execute: “python2.7 -V” and it will show the 2.7 version while executing “python -V” will result to the 2.4 version.
So how are we going to configure CentOS to use Python 2.7 as default instead of Python 2.4?
Easy. Just follow the following:
1. Add Python 2.7 lib to system lib:
ln -s /opt/python2.7/lib/libpython2.7.so /usr/lib
ln -s /opt/python2.7/lib/libpython2.7.so.1.0 /usr/lib
2. Create important links and cache
/sbin/ldconfig -v
3. Create a symbolic link:
ln -s /opt/python2.7/bin/python /usr/local/python
4. Check version by executing “python -V”. If you still see old version proceed to step 5.
5. Modify /etc/profile (as root)
vi /etc/profile
Look for the following entry “export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC” and put the following setting “pathmunge /opt/python2.7/bin/” above it.
It should look like this:
pathmunge /opt/python2.7/bin/
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
Then re-login system (very important), try “python -V” again.
6. (Very important last step) Make sure yum is just ok by executing “yum search php”. If it doesn’t return any errors then you are all good.
Credit:http://www.nerdsmind.com/how-to-upgrade-python-in-centos/