When building Python 3.2.3 from source on Ubuntu 12.04, the zlib module is not available.
I downloaded the official source distribution from python.org, and attempted to build and install it with the following commands.
tar xfa Python3.2.3.tar.bz2
cd Python-3.2.3
./configure --prefix=/opt/python3.2
make
sudo make install
The make command output includes the following.
Python build finished, but the necessary bits to build these modules were not found:
_curses _curses_panel _dbm
_gdbm _sqlite3 _ssl
_tkinter bz2 readline
zlib
After running make install and starting the interpreter, the zlib module cannot be imported.
I confirmed that the zlib1g-dev package is installed on my system.
I also found this similar question, which suggests adding the --with-zlib flag to the ./configure command. However, that returns an error that it is an unrecognized option and has no effect.
The solution is to install the Ubuntu package
dpkg-dev.The reason is explained here.
In short, recent versions of Ubuntu don’t store
libz.soin the standard/usr/liblocation, but rather in a platform specific location. For example, on my system is is in/usr/lib/x86_64-linux-gnu. This prevents Python’s build system from finding it.The
dpkg-devpackage installs thedpkg-architectureexecutable, which enables Python to find the necessary libraries.The original question was about Python 3.2.3. I also downloaded Python 2.7.3 and confirmed that the same problem exists, and this solution is applicable to it as well.