How to compile python from source and get a clean/minimal install?

10,545

Solution 1

It may be instructive to look at Debian's python2.7-minimal package (apt-get source python2.7-minimal). When in doubt, always look to see what others, especially the experts, are doing...

From debian/rules there:

: # Move the binary and the minimal libraries into $(p_min).
dh_installdirs -p$(p_min) \
        etc/$(PVER) \
        usr/bin \
        usr/include/$(PVER) \
        usr/share/man/man1 \
        $(scriptdir)/lib-dynload \
        $(scriptdir)/config
DH_COMPAT=2 dh_movefiles -p$(p_min) --sourcedir=$(d) \
        usr/bin/python$(VER) \
        usr/share/man/man1/python$(VER).1 \
        $(foreach i,$(MIN_MODS),$(scriptdir)/$(i).py) \
        $(foreach i,$(MIN_PACKAGES),$(scriptdir)/$(i)) \
        $(foreach i,$(MIN_ENCODINGS),$(scriptdir)/$(i)) \
        $(scriptdir)/config/Makefile \
        usr/include/$(PVER)/pyconfig.h \
        $(scriptdir)/site.py

The MIN_* variables are parsed out from README.Debian.in, which of course doubles as the package README but also thus becomes the authority on which modules to include.

Interesting stuff, I'd never looked at this before now. As for your question, the answer does seem that no, there isn't really a minimal target included in Python, but perhaps you could take the same approach Debian does to achieve your aims.

Solution 2

There is no such option - and it is a good thing keeping the installation as it is (perhaps you can chop of the test files manually). The .py files are handy for debugging. Apart from that: you really want to keep the full installation as it is. Dealing with stripped down Python installations as we see it on various Linux distributions is often a pain in the *.

Solution 3

Such options (if they exist in the software itself) are usually found in the configure script. Check configure -h.

Alternatively, you could try removing .py files if an identically named .pyc file exists. You can also remove the .pyo files. Removing .py and .pyo files would save 72396 kB under /usr/local/lib/python2.7 (that's around 47%) on my Python 2.7.3 installation.

Share:
10,545
Russ
Author by

Russ

Updated on June 15, 2022

Comments

  • Russ
    Russ about 2 years

    If you follow the simple configure -> make -> make install process for compiling python from source code, you end up with a very large install that includes a whole lot of files that are not necessary for a functional python environment. eg: All .py files are left in the installation (not just the .pyc or .pyo files), all the unit tests are carried over for each library in the lib folders, man pages are included, etc.

    Is there a canned way (make option?) to ignore or strip out the 'unnecessary' files during the install process so you are left with a minimalist, but fully functional, python distribution?

    If no pre-made procedure, what files can be stripped out, while being certain that the installation will still work on the machine it was installed?