1

In building python 3.7.2 from source, I did some testing and research to determine exactly which '-dev' packages I needed in install on Debian 9.8 in order to successfully build and install Python:

How to build and install Python 3.7.x from source on Debian 9.8

I was specifically trying to avoid pulling in a much larger set of packages than I need. A large set is fine but hopefully the top-level list is small, and I want to see the top-level list.

I wound up with a list of two that were required to make the build/install finish successfully, another that should be considered necessary, and eight more that were optional.

Could I have gotten to that same answer, or something close to it, using the information available in the apt command line tools (e.g. apt-cache)? If so, how?

Note: I tried sudo apt-get build-dep python3.5 as mentioned in https://devguide.python.org/setup/ but that seems suboptimal, because it is showing a much larger list of packages than the list I came up with.

$ sudo apt build-dep python3.5
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  autoconf automake autopoint autotools-dev blt-dev build-essential debhelper dh-autoreconf dh-strip-nondeterminism
  diffstat docutils-common dpkg-dev g++ g++-6 gettext intltool-debian libarchive-zip-perl libbluetooth-dev libbz2-dev
  libdb-dev libdb5.3-dev libdpkg-perl libexpat1-dev libffi-dev libfile-stripnondeterminism-perl libfontconfig1-dev
  libfreetype6-dev libgdbm-dev libice-dev libjs-sphinxdoc libjs-underscore liblzma-dev libmpdec-dev libncursesw5-dev
  libpng-dev libpthread-stubs0-dev libreadline-dev libsm-dev libsqlite3-dev libssl-dev libstdc++-6-dev libtinfo-dev
  libtool libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev m4
  net-tools pkg-config po-debconf python-babel-localedata python3-alabaster python3-babel python3-docutils
  python3-imagesize python3-jinja2 python3-pygments python3-roman python3-sphinx python3-tz quilt sharutils
  sphinx-common tcl-dev tcl8.6-dev time tk-dev tk8.6-blt2.5 tk8.6-dev x11proto-core-dev x11proto-input-dev
  x11proto-kb-dev x11proto-render-dev x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev xvfb
  zlib1g-dev
0 upgraded, 85 newly installed, 0 to remove and 1 not upgraded.
Need to get 44.3 MB of archives.
After this operation, 153 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Update: here's the full set that I'll get if I install the set of dev packages I found in the linked python question:

$ sudo apt install zlib1g-dev libffi-dev libssl-dev libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev
[sudo] password for parallels: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  build-essential bzip2-doc dpkg-dev g++ g++-6 libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libdpkg-perl libexpat1-dev libfile-fcntllock-perl libfontconfig1-dev libfreetype6-dev
  libice-dev libpng-dev libpng-tools libpthread-stubs0-dev libsm-dev libssl-doc libstdc++-6-dev libtinfo-dev
  libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev
  pkg-config tcl-dev tcl8.6-dev tk8.6-dev x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-render-dev
  x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev
Suggested packages:
  debian-keyring g++-multilib g++-6-multilib gcc-6-doc libstdc++6-6-dbg libice-doc liblzma-doc ncurses-doc
  readline-doc libsm-doc sqlite3-doc libstdc++-6-doc libxcb-doc libxext-doc libxt-doc tcl-doc tcl8.6-doc tk-doc
  tk8.6-doc
The following NEW packages will be installed:
  build-essential bzip2-doc dpkg-dev g++ g++-6 libalgorithm-diff-perl libalgorithm-diff-xs-perl
  libalgorithm-merge-perl libbz2-dev libdpkg-perl libexpat1-dev libffi-dev libfile-fcntllock-perl libfontconfig1-dev
  libfreetype6-dev libgdbm-dev libice-dev liblzma-dev libncursesw5-dev libpng-dev libpng-tools libpthread-stubs0-dev
  libreadline-dev libsm-dev libsqlite3-dev libssl-dev libssl-doc libstdc++-6-dev libtinfo-dev libx11-dev libx11-doc
  libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev pkg-config tcl-dev
  tcl8.6-dev tk-dev tk8.6-dev uuid-dev x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-render-dev
  x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev zlib1g-dev
0 upgraded, 54 newly installed, 0 to remove and 0 not upgraded.
Need to get 31.4 MB of archives.
After this operation, 106 MB of additional disk space will be used.
Do you want to continue? [Y/n]

“85 newly installed” using the build-dep approach; “54 newly installed” using my custom list. How can I narrow this gap?

  • Consulting apt packages only reveals what those actual packages depend on. The Python builds for Debian include all optional dependencies, because that is what people want. – OrangeDog Mar 11 '19 at 14:00
  • In the linked question, you wrote: “Everything you're asking for is in the package info”. But here you seem to be saying that what I'm asking for is not in the package info. Is it in there or not? – Charlie Mar 11 '19 at 14:03
  • apt-cache show PKGNAME lists the homepage and a description of what the package does. The Python documentation lists all the modules and what they do. – OrangeDog Mar 11 '19 at 14:06
  • The main problem I'm seeing right now is how to look at a short list of first-level dependencies, without being distracted by the clutter of everything pulled in transitively. – Charlie Mar 11 '19 at 14:19
  • 1
    "How can I narrow this gap?" - the fundamental problem is that you want the minimum dependencies to build the software. All the package system can give you is the minimum dependencies to build the package. – OrangeDog Mar 12 '19 at 15:14
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).

| improve this answer | |
  • Trying sudo apt-get build-dep python3.5-minimal: “The following NEW packages will be installed: autoconf automake autopoint autotools-dev blt-dev debhelper dh-autoreconf dh-strip-nondeterminism diffstat docutils-common [some output removed...] python-babel-localedata python3-alabaster python3-babel python3-docutils python3-imagesize python3-jinja2 python3-pygments python3-roman python3-sphinx python3-tz quilt sharutils sphinx-common time tk8.6-blt2.5 xvfb” This is pulling in a lot of python3.5 packages. But I'm building Python 3.7.2. I don't think I want those packages... – Charlie Mar 11 '19 at 15:08
  • @Charlie that's because the Debian package build tools themselves require Python. In general you need a lot more dependencies to build a package than to just install it. – OrangeDog Mar 11 '19 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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