Python 2.7.x and mod_wsgi on a CentOS 6
Read how to install Python 2.7.x on CentOS 6 and compile mod_wsgi against Python 2.7.x.

When you have installed CentOS 6 using the minimal image we need first to do some preparation. Fist login into your system and enable your eth0 at startup.

vi /etc/sysconfig/network-scripts/ifcfg-eth0

and set ONBOOT to yes.

Getting Python 2.7.x

The following explanations are based on a blog of Asim Teeshan and a post on Fire3Net.

First we need some development tools. Install the following once

yum install gcc make zlib-devel bzip2-devel openssl-devel

Now download the latest 2.7.x Python release and enable shared library during the configuation

cd /opt/

Extract and install it:

tar -zxvf Python-2.7.5.tgz
cd Python-2.7.5
./configure --enable-shared
make && make altinstall

Install Python setuptools for using easy_setup

sh setuptools-0.6c11-py2.7.egg

Before we can install mod_wsgi we need to install the http development libraries

yum install httpd httpd-devel

Now we are ready to compile mod_wsgi against Python 2.7.x

Download and unpack the latest version

tar -zxvf mod_wsgi-3.4.tar.gz
cd mod_wsgi-3.4.tar.gz
./configure --with-python=/usr/local/bin/python2.7

Make sure you specify the path to the python binary. You can find out where your Python binary is by issuing the following command:

whereis python

Once the configuration completed you can install it:

make && make install

If you run into problems along the lines cannot load shared library libpython2.7… then you need run the ldconfig first to tell where the* files are:

ln -s /usr/local/lib/ /usr/lib/
ln -s /usr/local/lib/ /usr/

Lastly we can install virtualenv as follow:

tar -zxvf virtualenv-1.10.1.tar.gz
cd virtualenv-1.10.1
python2.7 install

install psycopg2

wget --no-check-certificate
tar -zxvf psycopg2-2.5.1.tar.gz
cd psycopg2-2.5.1
vi setup.cfg

and add the following line


now install it

/usr/local/bin/python2.7 install

now creating a virtual env for you web application do it as follow

virtualenv-2.7 --system-site-packages ENV