Python Runtime Cropping

We have an application (Windows) with which we distribute the entire Python installation (including several third-party modules that we use), so we have consistency and therefore we do not need to install everything separately. This works very well, but the application is pretty huge.

Obviously, we are not using everything that is available at runtime. I would like to shorten the lead time to include only what we really need.

I plan to try py2exe, but I would like to try to find another solution that just helps me remove unnecessary parts of the Python runtime.

+6
python
source share
3 answers

Both py2exe and pyinstaller ( NOTE : for the latter, the version of SVN is used; one released is very long in the tooth ;-) performs its โ€œtrimmingโ€ through modulefinder , a standard library module for finding all the modules used by this Python script; you can, of course, use the latter yourself to identify all the necessary modules if you do not trust pyinstaller or py2exe to do this correctly and automatically on your behalf.

+5
source share

One trick I learned when trimming .py files to send: Delete all .pyc files in the standard library, and then run the application to the end (that is, to make sure that all the Python modules it needs are loaded). If you study the standard library directories, there will be .pyc files for all modules used .. py files without .pyc are the ones you don't need.

+6
source share

This compression py2exe page suggests using UPX to compress any DLL or .pyd files (which are actually just DLLs, still). Obviously, this does not help in trimming unnecessary modules, but it can / will crop the size of your distribution if this is a big problem.

+1
source share

All Articles