Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too much unecessary file in creating .exe #2118

Open
yasirroni opened this issue Oct 30, 2023 · 2 comments
Open

Too much unecessary file in creating .exe #2118

yasirroni opened this issue Oct 30, 2023 · 2 comments

Comments

@yasirroni
Copy link

To Reproduce
I'm trying to understand what happens under the hood of cx_freeze. Simple example of Python code

import time


print("Hello World!")
time.sleep(5)

Default run is using:

cxfreeze cx_freeze/hello_world.py --target-dir cx_freeze/dist

But, that tooks too long. Using exhaustive excludes, I can use:

cxfreeze cx_freeze/hello_world.py --target-dir cx_freeze/dist --exclude-modules asyncio,concurrent,ctypes,distutils,email,html,http,lib2to3,logging,multiprocessing,pydoc_data,pywin32_system32,tcl8,tcl8.6,test,tkinter,unittest,urllib,xml,xmlrpc.

The second command is bot faster and smaller in size. Both .exe works.

Expected behavior
Why so many packages and module that is not related is copied in creating the .exe?

Desktop (please complete the following information):

  • Platform information (e.g. Ubuntu Linux 22.04): Windows 10
  • OS architecture (e.g. amd64): Windows 64
  • cx_Freeze version [e.g. 6.11]: 6.15.10
  • Python version [e.g. 3.10]: 3.8
@yasirroni
Copy link
Author

After some investigations, the only module that must be exist are only collections, encodings, importlib, and library.zip.

All .pyd and .dll in lib/ also seems not necessary.

'libcrypto-1_1.dll',
'libffi-7.dll',
'libssl-1_1.dll',
'pyexpat.pyd',
'pywintypes38.dll',
'select.pyd',
'tcl86t.dll',
'tk86t.dll',
'unicodedata.pyd',
'win32api.pyd',
'win32evtlog.pyd',
'_asyncio.pyd',
'_bz2.pyd',
'_ctypes.pyd',
'_decimal.pyd',
'_elementtree.pyd',
'_hashlib.pyd',
'_lzma.pyd',
'_multiprocessing.pyd',
'_overlapped.pyd',
'_queue.pyd',
'_socket.pyd',
'_ssl.pyd',
'_testcapi.pyd',
'_tkinter.pyd',
'_win32sysloader.pyd'

@KennethNielsen
Copy link

KennethNielsen commented Mar 22, 2024

I'm not associated with the project, so I'm just guessing here. But the trimming down of the stdlib would require analyzing imports of not only the program being freezed, but also, any 3rd party dependencies it may depend on, which a) is a non trivial task and b) I don't think cx_Freeze does. It would be a worthy goal, but is probably also a lot of work.

For my own work I have similar size issues, but they are directly related to DLLs in a 3rd party package "PySide". Including all the DLLs (which I think is cx_Freeze default) of that, makes even simple PySide program several hundreds of megabytes in size, but again, going in and analyzing all PySide imports in my code and in all dependencies and coupling those Python imports to DLLs is non-trivial to say the least.

It is worth noting that a project like nuitka actually does something along those lines (at least it cuts down the bundled DLL's I don't know about stdlib), but it is a very different beast, so I don't know if it can be used for inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants