Sunday, August 11, 2013

Building Python from source on Ubuntu Linux


By Vasudev Ram

I recently had occasion to build Python 2.7.5 from its source code on Ubuntu Linux 12.04 LTS, for a project I'm working on.

I've built Unix and Linux packages from source many times before, including Oracle, Python, MySQL, wxPython, and others, but had not built a recent version of Python on a recent version of Linux. So I thought of doing it.

Here is how to build Python from source on Linux. The steps may vary some based on the version of Python you want to build, the Linux version, and so on. But the general principles are the same.

1. Download the Python source code from the downloads page at
python.org
, in one of the formats such as .tar.gz or .tgz.

2. Extract the compressed archive into some directory that you create:

mkdir build
mv Python-ver.tar.gz build
cd build
gunzip Python-ver.tar.gz (or .tgz)
tar xvf Python-ver.tar

3. Run:

./configure --prefix=PREFIX

where PREFIX is the path under which you want to install Python (after it is built).

There is also an --exec-prefix=EPREFIX option for configure.

If you give neither --prefix nor --exec-prefix, all files created by the build process are installed in default locations, such as /usr/bin and /usr/lib.

If you give --prefix=PREFIX only, all files created are installed under path PREFIX.

If you give both --prefix=PREFIX and --exec-prefix=EPREFIX, the architecture-independent files are installed under PREFIX and the architecture-dependent files are installed under EPREFIX.

There are also some other options for configure. See configure --help for details.

The advantage of installing from source, are that you have a lot more flexibility in how the package is built, what additional modules are built into the package, etc. See the documentation for more details.


4. Run:

make

This will build the Python executables, shared libraries, etc., from source.

5. Run:

make install

This will install the generated files into the default location or the location(s) specified by the PREFIX and EPREFIX values.

Now you are ready to try out your newly built Python.

Happy programming,
Vasudev


- Vasudev Ram - Dancing Bison Enterprises

Contact / Hire me



No comments: