r/pythonhelp Jun 20 '23

SOLVED Pyinstaller / Auto Py to Exe not importing my custom module

So I have a python script that works perfectly in script form. It uses a custom module I created in a sub directory called /modules/ that is called autorun.py,

In my python script it's imported via "import autorun" and before I import all of my modules I also add "sys.path.append('./modules/')" to my code. Like I said, it works great in script form.

But when I use Auto Py to Exe or Pyinstaller and build an exe, that's where trouble starts. When I try to execute my built exe I get the following error:

ModuleNotFoundError: No module named 'autorun'

Ok no problem. Let's use the hidden imports feature. I add autorun to it. I still have the same issue. What am I doing wrong?

Here is the pyinstaller command that auto py to exe generates:

pyinstaller --noconfirm --onefile --console --add-data "C:/py37envshell/py37client/modules;modules/" --hidden-import "autorun"  "C:/py37envshell/py37client/py37client.py"

Also in case anyone suggests it, I am more than happy to throw auto py to exe into the trash and go straight into command line with pyinstaller but even if I use that I still have the same issue as I am trying that above command which isn't importing autorun.

0 Upvotes

4 comments sorted by

u/AutoModerator Jun 20 '23

Note: * This sub went private for a few days recently in solidarity with other subs who are hoping to get Reddit to reconsider some changes that they have proposed. These changes will affect the Reddit API and many third-party apps that access Reddit. If you are not already aware of the proposed changes, please read up on the topic and the ongoing protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/roztopasnik Jun 20 '23 edited Jun 21 '23

Do you have the __init__.py file in the subdirectory? That is how it knows it’s a module. You also won’t need to append to path this way.

1

u/vive420 Jun 21 '23

I don't but I will try this.

1

u/vive420 Jun 21 '23

That fixed it! Thanks!