How can I determine build dependencies automatically?

Solution 1:

In general, apt-get build-dep PKGNAME will install all dependencies necessary to rebuild that package from source.

Alternatively, apt-cache will list package dependencies in various ways. For building you'd usually need the -dev version of the package. However this isn't going to cover all the required build tools (build-essential and so on).


For Python the easiest way is to read the documentation:

On Debian, Ubuntu, and other apt based systems, try to get the dependencies for the Python you’re working on by using the apt command.

First, make sure you have enabled the source packages in the sources list. You can do this by adding the location of the source packages, including URL, distribution name and component name, to /etc/apt/sources.list. Take Ubuntu Bionic for example:

deb-src http://archive.ubuntu.com/ubuntu/ bionic main

For other distributions, like Debian, change the URL and names to correspond with the specific distribution.

Then you should update the packages index:

$ sudo apt-get update

Now you can install the build dependencies via apt:

$ sudo apt-get build-dep python3.6

If that package is not available for your system, try reducing the minor version until you find a package that is available.

For a minimal build, it would be apt-get build-dep python3.6-minimal

For projects that provide a configure (such as cpython), the output should detail which dependencies are being looked for, and which are required to build. You can disable all optional dependencies (whether they're installed or not) using the provided switches (see ./configure --help).