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

If you follow a simple configure make make install process to compile python from source, you will get a very large installation that includes a large number of files that are not needed for the python functional environment. for example: all .py files remain during the installation process (not only .pyc or .pyo ), all unit tests are transferred for each library in the lib folders, man pages are included, etc.

Is there a canning path (make option?) To ignore or strip "unnecessary" files during the installation process so that you stay with a minimalist but fully functional python distribution?

If there is any preliminary procedure, what files can be deleted, being sure that the installation will still work on the machine, was it installed?

+4
source share
4 answers

You might find it helpful to check out the Debian python2.7-minimal package ( apt-get source python2.7-minimal ). When in doubt, always watch what others, especially experts, do ...

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 

MIN_* variables MIN_* parsed from README.Debian.in , which, of course, double as a README package, and also become the authority to enable modules.

Interesting stuff, I've never looked at this before. As for your question, the answer seems to be no, Python has no minimum goal, but maybe you can use the same approach that Debian takes to achieve your goals.

+7
source

There is no such option - and this is a good thing that supports the installation as it is (perhaps you can cut the test files manually). .Py files are convenient for debugging. In addition: you really want to keep the full installation as it is. Working with truncated Python installations, as we can see, on various Linux distributions, is often a pain in *.

+4
source

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

Alternatively, you can try deleting .py files if there is a file with the same .pyc identity. You can also delete .pyo files. Removing the .py and .pyo files would save 72396 kB under /usr/local/lib/python2.7 (about 47%) in my Python 2.7.3 installation.

+1
source

Note. Python has built-in modules, the Python executable, stand-alone, will work fine. You can remove any unnecessary modules, only you (or someone else) to determine which ones are not needed. Remember these dependencies of each module.

Some modules are built-in and therefore always are. For a list of built-in modules, upload the contents of sys.builtin_module_names .

Ex, with the standalone Python 3.4.1 executable compiled on the Ubuntu platform:

 >>> import sys >>> for m in sys.builtin_module_names: print(m) 

It says:

  • _ast
  • _codecs
  • _collections
  • _functools
  • _imp
  • _io
  • _locale
  • _operator
  • _sre
  • _stat
  • _string
  • _symtable
  • _thread
  • _tracemalloc
  • _warnings
  • _weakref
  • atexit
  • builtins
  • errno
  • faulthandler
  • gc
  • itertools
  • marshal
  • posix
  • pwd
  • signal
  • sys
  • xxsubtype
  • zipimport

There are private modules, and another 13 publicly available modules. Everything is embedded in the Python executable, standalone.

As already mentioned, you can delete any *.pyc and *.pyo , since everything is required for the module to work, these are *.py files.

0
source

Source: https://habr.com/ru/post/1341599/


All Articles