Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Once in a while I need to install a new Ubuntu (I used it both for desktop and servers) and I always forget a couple of libraries I should have installed before compiling, meaning I have to recompile, and it's getting annoying.

So now I want to make a complete list of all library packages to install before compiling Python (and preferably how optional they are).

This is the list I compiled with below help and by digging in It is complete for Ubuntu 10.04 and 11.04 at least:

build-essential (obviously)
libz-dev        (also pretty common and essential)
libreadline-dev (or the Python prompt is crap)

For Python 3.2 and later:


More optional:


Ubuntu has no packages for v1.8.5 of the Berkeley database, nor (for obvious reasons) the Sun audio hardware, so the bsddb185 and sunaudiodev modules will still not be built on Ubuntu, but all other modules are built with the above packages installed.


There are in Ubuntu 14.04 even more patches needed for Python 2.6, and 2.7 etc. I would recommend to instead checkout pyenv. It contains a script python-build (located in plugins/python-build/bin). With it you can install arbitrary Python versions like this:

$ ./python-build 2.7.8 /opt/python27

Where 2.7.8 is the version and /opt/python27 is the path it will be installed. Pyenv will download the Python version, apply the necessary patches and configure; make; make install for you.


Python 2.5 and Python 2.6 also needs to have LDFLAGS set on Ubuntu 11.04 and later, to handle the new multi-arch layout:

export LDFLAGS="-L/usr/lib/$(dpkg-architecture -qDEB_HOST_MULTIARCH)"

For Python 2.6, 2.7 and 3.0 you also need to explicitly enable SSL after running the ./configure script and before running make. In Modules/Setup there are lines like this:

#_ssl _ssl.c \
#       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#       -L$(SSL)/lib -lssl -lcrypto

Uncomment these lines and change the SSL variable to /usr:

_ssl _ssl.c \
       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
       -L$(SSL)/lib -lssl -lcrypto

Python 2.6 and 3.0 also needs Modules/_ssl.c modified to be used with OpenSSL 1.0, which is used in Ubuntu 11.10. At around line 300 you'll find this:

    else if (proto_version == PY_SSL_VERSION_SSL3)
        self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL2)
        self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL23)
        self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */

Change that into:

    else if (proto_version == PY_SSL_VERSION_SSL3)
        self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL2)
        self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
    else if (proto_version == PY_SSL_VERSION_SSL23)
        self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */

This disables SSL_v2 support, which apparently is gone in OpenSSL1.0.

Python 2.4 (yes, I still have some old projects that need 2.4) needs this patch to

---    2006-10-08 19:41:25.000000000 +0200
+++        2012-05-08 14:02:14.325174357 +0200
@@ -269,6 +269,7 @@
         lib_dirs = self.compiler.library_dirs + [
             '/lib64', '/usr/lib64',
             '/lib', '/usr/lib',
+           '/usr/lib/x86_64-linux-gnu'
         inc_dirs = self.compiler.include_dirs + ['/usr/include']
         exts = []
@@ -496,7 +497,8 @@
                 ssl_incs += krb5_h
         ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
-                                      '/usr/contrib/ssl/lib/'
+                                      '/usr/contrib/ssl/lib/',
+                                     'x86_64-linux-gnu'
                                      ] )

         if (ssl_incs is not None and

And it needs to be compiled with:

env CPPFLAGS="-I/usr/lib/x86_64-linux-gnu" LDFLAGS="-L/usr/include/x86_64-linux-gnu"  ./configure --prefix=/opt/python2.4
share|improve this question

4 Answers 4

up vote 11 down vote accepted

There are a few more. Normally, configure should remind you if anything is missing, and a few of them are optional. Here's my list:

libsqlite3-dev tk-dev

Notice there's no need to install Tk development libraries. Tk is provided through the repositories (for python 2.x and python 3)

share|improve this answer
Thanks, updated. Configure does remind you, but it just swooshes by, and sometimes it's not obvious what package to install. – Lennart Regebro Jan 15 '11 at 21:28
Accepted as the only one actually answering. :) I'll try to remember to add to this question the next time I need to install an Ubuntu. :) – Lennart Regebro Jan 16 '11 at 23:20
For Ubuntu 12.04, you'll want to change libreadline5-dev to libreadline-dev – Ehtesh Choudhury Mar 3 '14 at 21:40
Thanks for all of this. The text of your answer says 'no need to install tk dev libraries', but the list includes 'tk-dev'. Am I being dumb? – Jonathan Hartley Mar 15 '14 at 6:34
More recently, libbz2-dev and liblzma-dev should also be added. – Apalala May 20 '14 at 17:24

You should be able to install all build dependancies for Python with the build-dep option in apt-get

sudo apt-get build-dep python

       build-dep causes apt-get to install/remove packages in an attempt
       to satisfy the build dependencies for a source package.
share|improve this answer
That's interesting. But it installs loads of things that are clearly not strictly needed (libsgmls-perl!?), while it doesn't install neither libz-dev nor libreadline-dev (see above). – Lennart Regebro Jan 14 '11 at 18:27
This is very useful though when you apt-get source python. – Stefano Palazzo Jan 14 '11 at 18:29
For me, this also omits openssl, which means that after I build python, I can't install setuptools because its installer downloads over https. – Jonathan Hartley Mar 15 '14 at 9:35

To run certain types of tests you will need python-profiler

share|improve this answer

if you want to use Google App Engine SDK:

  • opensll
  • libssl-dev build-essential

libsqlite3-dev zlib1g zlib1g-dev

PIL 1.1.7


share|improve this answer
You don't need PIL to compile Python. :) – Lennart Regebro Jan 25 '11 at 23:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.