pyinstaller找不到隐藏的导入 [英] pyinstaller Hidden import not found
问题描述
我正在使用pyinstaller.在我的脚本中有:
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
但是当我运行可执行文件时,它给了我:ModuleNotFoundError: No module named 'toml'
but when I run the executable it gave me: ModuleNotFoundError: No module named 'toml'
所以我尝试了这个:
pyinstaller main.py --hidden-import toml --onefile --clean --name myApp
现在pyinstaller说:ERROR: Hidden import 'toml' not found
and now pyinstaller says: ERROR: Hidden import 'toml' not found
推荐答案
找到了答案.如果您使用的是虚拟环境(如Pipenv,pyenv,venv),则需要在该环境的上下文中运行pyinstaller.所以...
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 ....
而且,正如mosegui指出的那样,您应该将配置标志放在文件名之前:
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.
这几天,我使用诗歌,所以一旦有了诗歌环境,我就只需poetry shell
和/或poetry run pyinstaller ...
.每当您使用poetry run <some cmd sequence>
时,它都会在当前虚拟环境的上下文中运行任何命令序列.我相信pipenv run
可以完成类似的工作,但诗歌对我而言总是更好.
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.
这篇关于pyinstaller找不到隐藏的导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!