I'm using pyinstaller. In my script there is:
import toml
config = toml.load('config.toml')
I compiled my script with:
pyinstaller main.py --onefile --clean --name myApp
but when I run the executable it gave me: ModuleNotFoundError: No module named 'toml'
So I tried this:
pyinstaller main.py --hidden-import toml --onefile --clean --name myApp
and now pyinstaller says: ERROR: Hidden import 'toml' not found
Found the answer. If you are using a virtual environment (Like Pipenv, pyenv, venv) you need to run pyinstaller in the context of that environment. So...
pip install pyinstaller
python -m PyInstaller main.py ....
Also, as mosegui pointed out, you should put your config flags before the file name:
pyinstaller --hidden-import toml --onefile --clean --name myApp main.py
though this was so long ago that I'm not sure if that was actually an issue for me.
These days I use Poetry so once I have a Poetry environment I just poetry shell
and/or poetry run pyinstaller ...
. Anytime you use poetry run <some cmd sequence>
it runs whatever your command sequence is in the context of the current virtual environment. I believe pipenv run
accomplishes a similar thing but Poetry always works better for me.