49

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 setup.py. 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)
libncursesw5-dev
libssl-dev
libgdbm-dev
libsqlite3-dev
libbz2-dev

For Python 3.2 and later:

liblzma-dev

More optional:

tk-dev
libdb-dev

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.

UPDATE

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.

END UPDATE

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=/usr/local/ssl
#_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=/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 */
#ifndef OPENSSL_NO_SSL2
    else if (proto_version == PY_SSL_VERSION_SSL2)
        self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
#endif
    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 setup.py:

--- setup.py    2006-10-08 19:41:25.000000000 +0200
+++ setup.py        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/local/ssl/lib',
-                                      '/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

4 Answers 4

27

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:

build-essential
libncursesw5-dev
libreadline-gplv2-dev
libssl-dev
libgdbm-dev
libc6-dev
libsqlite3-dev
libbz2-dev
libffi-dev
8
  • 1
    Thanks, updated. Configure does remind you, but it just swooshes by, and sometimes it's not obvious what package to install. Jan 15, 2011 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. :) Jan 16, 2011 at 23:20
  • 1
    For Ubuntu 12.04, you'll want to change libreadline5-dev to libreadline-dev Mar 3, 2014 at 21:40
  • 3
    More recently, libbz2-dev and liblzma-dev should also be added.
    – Apalala
    May 20, 2014 at 17:24
  • 2
    16.10 has replaced libreadline5-dev with libreadline-gplv2-dev
    – jmunsch
    Jan 1, 2017 at 13:13
18

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
       build-dep causes apt-get to install/remove packages in an attempt
       to satisfy the build dependencies for a source package.
5
  • 1
    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). Jan 14, 2011 at 18:27
  • This is very useful though when you apt-get source python. Jan 14, 2011 at 18:29
  • 1
    For me, this also omits openssl, which means that after I build python, I can't install setuptools because its installer downloads over https. Mar 15, 2014 at 9:35
  • this is what the official docs seem to recommend too: docs.python.org/devguide/setup.html
    – hwjp
    Mar 7, 2017 at 9:56
  • 1
    For greater precision you can use the command sudo apt-get build-dep python3.x (replace 3 and x with your preferred version as needed - though sometimes as in my case 3.6 wasn't yet available so I used 3.5 instead)
    – JxAxMxIxN
    Jul 3, 2017 at 18:31
2

if you want to use Google App Engine SDK:

  • opensll
  • libssl-dev build-essential

libsqlite3-dev zlib1g zlib1g-dev

PIL 1.1.7

:)

1
  • You don't need PIL to compile Python. :) Jan 25, 2011 at 23:42
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .