Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 397
Russ Avatar asked Feb 28 '11 06:02

Russ


2 Answers

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.

like image 76
zigg Avatar answered Sep 28 '22 08:09

zigg


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 *.

like image 29
Andreas Jung Avatar answered Sep 28 '22 09:09

Andreas Jung