pyinstaller Hidden import not found
Asked Answered
M

2

4

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

Melgar answered 26/7, 2019 at 21:25 Comment(3)
python is complaining that it can't find toml package. are you sure you have that installed? try pip install toml before running pyinstallerImmixture
yes. It is installed via pipenv and I am in pipenv shellMelgar
@Immixture your comment helped me find it. thanksMelgar
M
14

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.

Melgar answered 26/7, 2019 at 22:32 Comment(3)
This was oddly the only solution after 6 hours of searching for a reason why my script would not compile. This should definitely have more upvotes.Shannon
Hey, I am having the same problem, the command that I run was "pyinstaller --hidden-import tensorflow --onefile main.py" but it still says "Hidden import tensorflow not found!"Phage
re-ordering parameters didn't work for me, still couldn't find the modulesJustis
V
1

I know this is a very belated answer, but I will just leave an observation here in case someone finds himself/herself in a similar situation:

Even if you have toml installed, pyinstaller will not find the hidden import because you are passing the config flags after your script name, instead of before, so the command executes up until your script name and disregards the rest. Try:

pyinstaller --hidden-import toml --onefile --clean --name myApp main.py

instead of your current:

pyinstaller main.py --hidden-import toml --onefile --clean --name myApp
Va answered 10/7, 2020 at 7:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.