[GH-ISSUE #82] Importing from directory named the same as the main py file does not work #80

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

Originally created by @evilmrhenry on GitHub (Dec 14, 2019).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/82

hello_world.py:

from hello_world import importer
print("running main")
importer.runme()

hello_world\importer.py:

print("import complete")
def runme():
    print("running function")

(Also toss an init.py file in there as well.)

If run directly via python, the result is
import complete
running main
running function
If compiled with auto-py-to-exe first (single file mode), nothing is output, even if the exe is moved to a different directory. Changing the directory name causes everything to work as expected. If debug is turned on, it outputs a bunch of stuff, but no obvious warnings about this. I would prefer this to work, or failing that, have it output a useful warning somewhere.

Originally created by @evilmrhenry on GitHub (Dec 14, 2019). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/82 hello_world.py: from hello_world import importer print("running main") importer.runme() hello_world\importer.py: print("import complete") def runme(): print("running function") (Also toss an __init__.py file in there as well.) If run directly via python, the result is import complete running main running function If compiled with auto-py-to-exe first (single file mode), nothing is output, even if the exe is moved to a different directory. Changing the directory name causes everything to work as expected. If debug is turned on, it outputs a bunch of stuff, but no obvious warnings about this. I would prefer this to work, or failing that, have it output a useful warning somewhere.
kerem closed this issue 2026-02-26 12:20:25 +03:00
Author
Owner

@brentvollebregt commented on GitHub (Dec 14, 2019):

If you put a print statement in hello_world\__init__.py, after packaging and executing the output you can see that the init file of the hello_world package is what's being run (due to the print being executed). This has occurred due to the filename being packaged and a module in the same directory named the same - thus PyInstaller is taking the package over the specified file.

This unfortunately is not a bug with auto-py-to-exe directly and lies in PyInstaller. I see that if you remove the import statement and importer.runme() from hello_world.py, PyInstaller will still package the module.

<!-- gh-comment-id:565756428 --> @brentvollebregt commented on GitHub (Dec 14, 2019): If you put a print statement in hello_world\\_\_init\_\_.py, after packaging and executing the output you can see that the init file of the hello_world package is what's being run (due to the print being executed). This has occurred due to the filename being packaged and a module in the same directory named the same - thus PyInstaller is taking the package over the specified file. This unfortunately is not a bug with auto-py-to-exe directly and lies in PyInstaller. I see that if you remove the import statement and `importer.runme()` from hello_world.py, PyInstaller will still package the module.
Author
Owner

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

Closing due to no response from the issue author.

<!-- gh-comment-id:612539741 --> @brentvollebregt commented on GitHub (Apr 12, 2020): Closing due to no response from the issue author.
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#80
No description provided.