[GH-ISSUE #116] Automatically ignore __pycache__ folders? #109

Closed
opened 2026-02-26 12:20:31 +03:00 by kerem · 2 comments
Owner

Originally created by @ganego on GitHub (Aug 12, 2020).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/116

So with the ´pycache ` folder being for compiled python code, it seems to not make sense to bundle code that was compiled with my Python version and my Windows version to a package I'd distribute - right?
Happens when I add a folder.

Can those files actually even be used with the exe? If so, maybe it would make sense?
But I never see those files being created by the exe.

Or is this byte-code already put in the exe? But then why would I still need to include the folders with my other .py files.

So I guess the exe does not use compiled python code?

Is there an automatic way to ignore it (did not find one), or do I have to remove it manually after packaging the .exe?

Thank you

Originally created by @ganego on GitHub (Aug 12, 2020). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/116 So with the ´__pycache__ ` folder being for compiled python code, it seems to not make sense to bundle code that was compiled with my Python version and my Windows version to a package I'd distribute - right? Happens when I add a folder. Can those files actually even be used with the exe? If so, maybe it would make sense? But I never see those files being created by the exe. Or is this byte-code already put in the exe? But then why would I still need to include the folders with my other .py files. So I guess the exe does not use compiled python code? Is there an automatic way to ignore it (did not find one), or do I have to remove it manually after packaging the .exe? Thank you
kerem closed this issue 2026-02-26 12:20:31 +03:00
Author
Owner

@brentvollebregt commented on GitHub (Aug 12, 2020):

auto-py-to-exe uses PyInstaller for packaging, so taking a read of the docs I found:

PyInstaller embeds compiled python code (.pyc files) within the executable.

Taking a look inside the base_library.zip file generated (can easily be seen in one-folder mode) it's clear that PyInstaller has packaged .pyc files rather than .py files.

Why does it not make sense to package these compiled scripts? Yes, they may have been created with the specific version of Python you used to package, but the exact same interpreter that created them will be packaged with the pyc files. In terms of the OS compatibility, I have only seen architecture be an issue and I believe that is due to something other than complied Python scripts.

I haven't seen a flag or option to stop using pyc files before - most likely because pyc files are faster and they run just as fine.

<!-- gh-comment-id:673086256 --> @brentvollebregt commented on GitHub (Aug 12, 2020): auto-py-to-exe uses PyInstaller for packaging, so taking a [read of the docs](https://pyinstaller.readthedocs.io/en/stable/advanced-topics.html#python-imports-in-a-bundled-app) I found: > _PyInstaller_ embeds compiled python code (`.pyc` files) within the executable. Taking a look inside the `base_library.zip` file generated (can easily be seen in one-folder mode) it's clear that PyInstaller has packaged .pyc files rather than .py files. Why does it not make sense to package these compiled scripts? Yes, they may have been created with the specific version of Python you used to package, but the exact same interpreter that created them will be packaged with the pyc files. In terms of the OS compatibility, I have only seen architecture be an issue and I believe that is due to something other than complied Python scripts. I haven't seen a flag or option to stop using pyc files before - most likely because pyc files are faster and they run just as fine.
Author
Owner

@ganego commented on GitHub (Aug 12, 2020):

I tested and the pyc files - that are in a separate included folder - are accessed when the exe loads. But I just had another idea and I did another test to check if they are actually used, and it seems they are in fact used when running the exe. For that I simply deleted parts of the pyc file from the included folder and once this code was supposed to be called, the app crashed.

Traceback

Traceback (most recent call last):
  File "xx.py", line 816, in keyPressEvent
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 779, in exec_module
  File "<frozen importlib._bootstrap_external>", line 911, in get_code
  File "<frozen importlib._bootstrap_external>", line 580, in _compile_bytecode
EOFError: marshal data too short
<!-- gh-comment-id:673105157 --> @ganego commented on GitHub (Aug 12, 2020): I tested and the pyc files - that are in a separate included folder - are accessed when the exe loads. But I just had another idea and I did another test to check if they are actually used, and it seems they are in fact used when running the exe. For that I simply deleted parts of the pyc file from the included folder and once this code was supposed to be called, the app crashed. Traceback ``` Traceback (most recent call last): File "xx.py", line 816, in keyPressEvent File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 779, in exec_module File "<frozen importlib._bootstrap_external>", line 911, in get_code File "<frozen importlib._bootstrap_external>", line 580, in _compile_bytecode EOFError: marshal data too short ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/auto-py-to-exe#109
No description provided.