PyInstaller mistakes local module for package distribution

234 views
Skip to first unread message

Stone Oliver

unread,
Feb 10, 2021, 4:12:53 AM2/10/21
to PyInstaller

Hi,

Python newbie here. I have scoured stackexchange, reddit, and your documentation to no avail, but there is a fair chance I've missed something stupid. Sorry in advance.

I have spent several weeks attempting to create a .exe for a script which contains a line:
'import local module 1'
Inside local module 1 there are several lines:
'from local module 2 import thing 2
from local module 3 import thing 3'

No matter the details of how I run PyInstaller I always get an error stating that "The 'local module 2' distribution was not found and is required by the application". The problem I have is that this is not a distribution, it is only a local module. I have tried adding 'local module 2' and 'thing 2' to hidden imports. I also know the relevant scripts are in the path (as seen in pathex). I do not understand how to tell PyInstaller that the local module is only a local script. I also tried an older version  PyInstaller3.4 but I only run into more problems I don't understand involving a failure to execute the json decoder. You can roast me all you want but please help me.

bwoodsend

unread,
Feb 10, 2021, 9:38:48 AM2/10/21
to PyInstaller

The “distribution was not found and is required by the application” means that you’re using pkg_resources.get_distribution("local_module_2") somewhere? This should only work (PyInstaller or otherwise) if local module 2 is a fully fledged package. What do you mean by local module? Is it just a folder containing Python scripts or does it have a setup.py/setup.cfg or pyproject.toml?

Oliver, Stone

unread,
Feb 11, 2021, 1:19:39 PM2/11/21
to pyins...@googlegroups.com
Local module 2 is only a single python file, localmodule2.py. This is why I am confused as to why PyInstaller seems to think it is a fully fledged package/distribution. Nowhere in my code in any of my python files do I use 'pkg_resources.get_distribution("local_module_2")'. The only way it is ever referenced is with "from localemodule 2 import thing 2'. I also tried changing that to 'import localmodule2' with no difference. The strange thing is that it is only this one file which is being mistaken. If I remove the line 'from local module 2 import thing 2' from my code then PyInstaller does successfully build the app. Of course the app does not run because it is missing local module 2 though, but this means it has successfully found all the other files localmodule3, localmodule4, etc, that it needed, and never accidentally mistook them for a distribution. Is there maybe some code inside local module 2 itself which makes PyInstaller believe it is more than just a .py file?

Thank you for your time,
_S

--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/54cd6e6c-4c67-4b08-98a2-5a76101af5a2n%40googlegroups.com.

bwoodsend

unread,
Feb 11, 2021, 2:33:40 PM2/11/21
to PyInstaller

Hmm, getting weird then. Can we have the full stacktrace/error message? I’d also double check for anything else with the same name as local_module_2:

python -c "from local_module_2 import __file__; print(__file__)"

Make sure that __file__ is what you expect it to be….

Reply all
Reply to author
Forward
0 new messages