Oliver Nassar

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar


Installing Python 3.1.3 on Ubuntu 10.10

View more posts

This quick guide allowed me to install Python 3.1.3 on an Ubuntu 10.10 stack. Not sure about the libraries that come with it, so I may need to do a follow up to compile in some extra goodies. Worth noting is that 10.10 comes with Python 2.6 I think, but I wanted to get a fresh one in and integrate it with Apache2 properly.

The following are the steps I performed to get the Python 3.1.3 binary installed:

cd
wget http://python.org/ftp/python/3.1.3/Python-3.1.3.tgz
tar -xvzf Python-3.1.3.tgz
rm Python-3.1.3.tgz
cd Python-3.1.3/
./configure --prefix=/usr/local/python3.1.3
make
make test
sudo make install
sudo ln -s /usr/local/python3.1.3/bin/python3.1 /usr/bin/python3.1.3
cd
rm -rf Python-3.1.3/

Okay good. Python's up and running. Test it by running python3.1.3 in the terminal, executing whatever you want.

Now, setup apache to compile python files:

sudo apt-get install -y libapache2-mod-python

You'll now need to open your apache config file (default, or site/domain specific) and add the following to the vhost declarations:

AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On

This enables *.py files to be executed. Alternatively, there is an option to develop using *.psp files, which allows you to write python inline in the following format:

<h1><% req.write("Hello!") %></h1>

Note that only *.py files or *.psp files can be activated by Apache at once (well, I tried having them both, and it didn't work). Throw in the following apache directives for the psp files:

AddHandler mod_python .psp
PythonHandler mod_python.psp
PythonDebug On

There ya have it. Beginning to end took me maybe 2 hours, which is pretty descent. 10.10 comes with python already installed, so maybe all of this wasn't necessary, but at least I have it up and running within Apache now, ready to start serving page :)

Links that helped:

Welcome to Ubuntu: Howto: Install Python 2.5.5 on Ubuntu 10.04 Lucid Lynx
Embedding Python In Apache2 With mod_python (Debian Etch)