Pyinstaller 在不存在的文件夹中搜索

Pyinstaller searches in nonexistent folder

我一直在尝试使用 pyinstaller 从 python 脚本构建可执行文件,但是,一旦我 运行 使用

pyinstaller --onefile stock_visual.py

在 windows cmd 中生成文件,每当我 运行 它时,我都会收到以下错误:

Traceback (most recent call last):
  File "stock_visual.py", line 6, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "c:\users\verdi\github\jiostocks\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "lib\site-packages\dash_core_components\__init__.py", line 12, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Verdi\AppData\Local\Temp\_MEI112322\dash_core_components\package-info.json'
[4824] Failed to execute script stock_visual

现在,我看到几个人遇到了类似的问题,但他们是因为需要手动导入一个动态导入的库,如 pyinstaller 文档中所述:

https://pythonhosted.org/PyInstaller/when-things-go-wrong.html#listing-hidden-imports

这在我的情况下似乎不起作用,甚至没有创建它正在寻找 dash_core_components 文件的目录:

附带说明一下,如果我不使用 --onefile 选项,也会出现同样的问题,但文件夹在项目内部,在 \build 文件夹中,但程序查找库的目录不会两者都存在。

到目前为止,我已经尝试了 --onedir 选项,包括我之前所说的手动库,基本上 pyinstaller troubleshooting web page 中所说的一切以及 py2exe 和 cx freezer 替代方案,它们也给出了自己的错误.

我正在尝试使用构建器的脚本可以在 this repo 中找到,我已经尝试使用其他脚本和 运行s 没有任何问题。

我正在使用 windows10 64 位,python3.8 和一个封闭的虚拟环境 (venv),其中包含在所述存储库中的 requirements.txt 文件中列出的所有库。

任何关于如何解决此问题的提示都将不胜感激。

您需要为 dash_*** 模块创建一个挂钩文件。以下可能会起作用:

# hooks/hook-dash_core_components.py

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all('dash_core_components')

将其保存在文件旁边目录下名为 hook-dash_core_components.py 的文件中:

- myfile.py
- hooks
  - hook-dash_***.py

并在编译时添加一个选项; --additional-hook-dir=hooks.