pyinstaller/pyinstaller — pull request #8 by bara86 (2012-05-04 13:42:15+00:00)
Title: Use system libraries

The feature I want to develop is the possibility to choose whether to bundle or not the system libpython.
If the target computer already has a libpython, adding it to application is a waste of space. The idea is to add to PyInstaller the ability to remove the standard library from the application and use the system libpython.

To develop this feature I'll work on builder and bootloader: the overall plan is to have the builder not to bundle the libpython, and the bootloader to use the system libpython.

In class Analysis in module build.py it will be possible to pass a new parameter called use_system_library whose default value is False (in this case the build system libpython is bundled as usual), instead if the value is True the application must use the system library and the libpython is not included in the Analysis' results. Excluding the bundling of libpython will be made after the function fixMissingPythonLib - after the invocation of this function, we can be sure that the libpython has been located somehow by the build system and that it's already scheduled for inclusion, so it makes sense to just remove it from the Analysis' results at this point.

The choice whether to import or not the libpython is done in Analysis because this phase is always done and doing this choice after that could lead to code duplication, or to necessity to pass superfluous information (e.g. an EXE with exclude_binaries=True doesn't need the list of binaries, because COLLECT will collect them - so should I add this option as an argument to EXE, I would still have to pass it the full list of binaries).

To save this information I've not change the cookie structure, but change the value in pyvers to negative if the user wants to use the Python system library.

In bootloader the idea is to change the loadPython function, so that before throwing an error when not finding the bundled libpython, the function checks the presence of a system libpython (how this search is performed in detail depends on the operating system). In my implementation the system libpython's version must match the same that could be found on the build machine. If nothing is found the program throws an error.

The feature is developed for Linux and Windows and I've try it on a Ubuntu 11.04 64 bit with Python 2.7, Ubuntu 6.06 with Python 2.4, Windows 7 32 bit with Python 2.6 and Windows 7 64 bit with Python 2.7.

If somebody wants to comment on the above, I'll gladly take your suggestions. If somebody try this feature on other OS or Python version, I appreciate the help.

Matteo