Installing libboost-python-dev for python3 without installing python2.7

I am trying to install boost bindings for python3 on Ubuntu Xenial, but it pulls in whole python2.7 dependency tree. I do not want or need python2.7 on my system (Docker image). Is there a way to install only python3 bindings?


I have resolved to compiling and installing boost myself (I also installed/compiled Python 3.6 myself.). I have in my Dockerfile now:

# We have to compile it ourselves against the custom Python and cannot use Debian package.
# Includes a symlink workaround for: https://svn.boost.org/trac10/ticket/11120
RUN cd /usr/src && \
 wget --no-verbose https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz && \
 tar xzf boost_1_65_1.tar.gz && \
 cd boost_1_65_1 && \
 ln -s /usr/local/include/python3.6m /usr/local/include/python3.6 && \
 ./bootstrap.sh --with-python=$(which python3) && \
 ./b2 install && \
 rm /usr/local/include/python3.6 && \
 ldconfig && \
 cd / && rm -rf /usr/src/*

You have three options:

1. Build Boost.Python yourself

This is the option I recommend: it's clean, there's no risk to mess up your system and you have full control on what you get. Moreover1

Boost.Python is a separately-compiled (as opposed to header-only) library

so you can just build that. Download the archive and follow the instruction on the Getting Started guide. (This is what OP did.)


2. Use dpkg to avoid installing unwanted dependecies

If you don't want to build Boost.Python yourself, you can bypass apt (and its dependencies cheking) with dpkg.

Let's say you want to install a package named foo which depends on bar and baz, but you don't actually need baz.

apt download foo bar
sudo dpkg --ignore-depends=baz --install foo.deb bar.deb

Notice that apt will still complain about unresolved dependencies (but hey, that's its job), so the problem is not entirely solved: you just swept it under the carpet.

This option is quicker than the previous one, but I wouldn't recommend it.


3. Use equivs to fool apt

This is new to me. Apparently, you can create dummy packages to fulfill the dependencies. In this way, you don't have to install unwanted/unnecessary packages and apt will not complain about it.

As I said, I've never used equivs before, but you can find out more about it here.