Python on Debian from sourcecode update (altinstalling development branch 3.2 rc2)

Just though I’d post an update on my earlier post about installing Python 3.1.3 from source code on Debian Linux.

Although I wouldn’t encourage you to use it as your main environment some of you may be interested in trying out the latest development branch of Python to test new features or to help with finding and reporting bugs.

As of writing this, the lattest release is 3.2 rc2.

http://www.python.org/ftp/python/3.2/Python-3.2rc2.tgz

If you’d like to test out the development branch without interfering with your main install of Python you can use Pythons ‘altinstall’ feature.

Follow my previous guide on compiling Python 3.1.3 and when you reach the final stage instead of running;

debian:/#make && make install

Run the following instead;  (please note you will need appropriate permission to write to system folders to run either ‘make install’ or ‘make altinstall’.)

debian:/#make && make altinstall

Instead of installing the Python binary under the default name of  ‘python3’, ‘altinstall’ will incorporate the full version number in to the binary name leaving the original stable branch binary undisturbed.

You can run the ‘altinstall’ by typing;

debian:/#python3.2

Link to my previous guide:
Installing Python 3.1.3 from source, the full works (Debian Linux 5.x lenny)

Installing Python 3.1.3 from source, the full works (Debian Linux 5.x lenny)

So previously I’d posted about getting Python 3.1 installed from source on OS X. This time I’ll be talking about installing Python 3.1.3 on Debian Linux 5.x lenny.

Although this guide is specific to Debian lenny it should be applicable to other Linux distros’ based on Debian such as Ubuntu and can probably be adapted to work on other distros’.

First you’ll need to download the Python source code, you can do so by following this link. Python 3.1.3

You can also download and uncompress the file by running the following commands from the terminal

debian:/# wget http://www.python.org/ftp/python/3.1.3/Python-3.1.3.tar.bz2

debian:/# tar -xvf ./Python-3.1.3.tar.bz2

To build programs from source you’ll need to install gcc and associated files which can be done as follows;

debian:/# apt-get install build-essential

The first time I tried to compile the Python source-code I was presented with the following output….

Python build finished, but the necessary bits to build these modules were not found:
_curses            _curses_panel      _dbm
_gdbm              _hashlib           _sqlite3
_ssl               _tkinter           bz2
readline           zlib
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.

I should expect on most fairly default installs of Debian you’ll also be missing the same components. If you wanted you could run Python as it is but you’ll be missing many important features.

If you follow the rest of this guide I’ll show you how to install all the required files for a fully featured Python build.

To install the missing components you should run the following from the terminal;

debian:/# apt-get install zlib1g-dev libncurses5-dev libreadline5-dev libssl-dev libbz2-dev libsqlite3-dev tk-dev libgdbm-dev

Now you have all the required components we can try to compile the code.

Navigate through to the directory where you extracted the Python files and run the following.

debian:/#./configure && make && make install

If everything has gone well Python 3.1.3 should now be compiled and installed.

you can run the Python interpreter by running the following;

debian:/#python3

I hope this guide has been helpful. Happy coding.