Wednesday Feb 22
Jan
03/12
Python 2.7 on CentOS 5.6
Last Updated on Tuesday, 10 January 2012 01:52
Written by Cody Snider
Tuesday, 3 January 2012 07:55

Here you have it, folks. A shell script that will handle all the ugliness associated with installing Python 2.7 on CentOS 5.6 (and probably CentOS 5.7, too).

Use the following command in your shell (the easy way):

wget -q -O http://codingwithcody.com/downloads/python_27_on_centos_56/install.sh | sh

Alternately, you can download and run it manually: Download install.sh

Here are the tarballs used just in case the servers hosting them go down and you’re eager to get Python 2.7 working:

And, just FYI, here’s the contents of install.sh:

yum -y install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make
 
cd /var/tmp
wget http://sqlite.org/sqlite-amalgamation-3.7.3.tar.gz
tar xfz sqlite-amalgamation-3.7.3.tar.gz
cd sqlite-3.7.3/
./configure
make
make install
 
cd /var/tmp
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar xvfz Python-2.7.1.tgz
cd Python-2.7.1
./configure --prefix=/opt/python2.7.1 --with-threads --enable-shared
make
make install
 
touch /etc/ld.so.conf.d/opt-python2.7.1.conf
echo "/opt/python2.7.1/lib/" >> /etc/ld.so.conf.d/opt-python2.7.1.conf
ldconfig
 
ln -sf /opt/python2.7.1/bin/python /usr/bin/python2.7
 
cd /var/tmp
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.egg --prefix=/opt/python2.7.1
 
/opt/python2.7.1/bin/easy_install pip
ln -sf /opt/python2.7.1/bin/pip /usr/bin/pip
 
pip install virtualenv
ln -sf /opt/python2.7.1/bin/virtualenv /usr/bin/virtualenv
 
mv /usr/bin/python /usr/bin/python-backup
ln -s /usr/bin/python2.7 /usr/bin/python

Any improvements are more than welcome. Enjoy and happy coding!


3 Comments
  1. CommentsEmre   |  Tuesday, 10 January 2012 at 12:08 pm

    Great! It installed fine for me! thanks!

  2. CommentsEmre   |  Tuesday, 10 January 2012 at 1:06 pm

    This typo needs to be corrected: bzip2-develsqlite-devel in the 1st line of the install.sh file.

  3. CommentsCody Snider   |  Tuesday, 10 January 2012 at 1:51 pm

    Good catch, Emre. Applying that correction now.


Leave a Reply