2

我制作了一个流线型应用程序作为预测程序的前端,然后我创建了一个 pyinstaller 可执行文件来运行该应用程序。当我运行可执行文件时出现问题,我收到以下错误:pkg_resources.DistributionNotFound: The 'streamlit' distribution was not found and is required by the application使用此回溯:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
  File "<frozen importlib._bootstrap>", line 968, in _find_and_load
  File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "/opt/anaconda3/envs/Python35/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages/streamlit/__init__.py", line 75, in <module>
  File "site-packages/pkg_resources/__init__.py", line 476, in get_distribution
  File "site-packages/pkg_resources/__init__.py", line 352, in get_provider
  File "site-packages/pkg_resources/__init__.py", line 895, in require
  File "site-packages/pkg_resources/__init__.py", line 781, in resolve

pkg_resources.DistributionNotFound: The 'streamlit' distribution was not found and is required by the application
[48095] Failed to execute script main

该文件是使用以下命令创建的:pyinstaller --onefile -w main.py

这是在 Conda 环境中使用 python 3.5.6 在 macOS Catalina 上设置的

如果有任何我可能遗漏的细节可以对此有所帮助,请告诉我。

4

1 回答 1

2

看起来您需要添加一个hook名为hook-streamlit.py以下内​​容的文件

from PyInstaller.utils.hooks import copy_metadata

datas = copy_metadata('streamlit')

您还需要将--additional-hooks-dir标志传递给您的pyinstaller命令。

如果您已将挂钩文件放在与您的 python 脚本相同的目录中,您可以像这样指定它

pyinstaller --onefile --additional-hooks-dir=. -w main.py

于 2020-03-04T15:33:07.267 回答