在pyinstaller可执行程序中找不到Streamlit发行版

时间:2020-02-29 21:23:13

标签: python pyinstaller streamlit

我制作了一个精简的应用程序以充当预测程序的前端,然后创建了一个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上设置的

如果有任何我可能错过的详细信息对此有所帮助,请告诉我。

1 个答案:

答案 0 :(得分:1)

您似乎需要添加一个名为hook的{​​{1}}文件,其中包含以下内容

hook-streamlit.py

您还需要将from PyInstaller.utils.hooks import copy_metadata datas = copy_metadata('streamlit') 标志传递给--additional-hooks-dir命令。

如果将钩子文件放置在与python脚本相同的目录中,则可以这样指定

pyinstaller