【问题标题】:Error building executable using pyinstaller on Ubuntu在 Ubuntu 上使用 pyinstaller 构建可执行文件时出错
【发布时间】:2020-06-22 14:40:03
【问题描述】:

我编写了一个小 Python 脚本来了解如何使用 pyinstaller 构建可执行文件。脚本是

import numpy
import scipy

from scipy.optimize import linear_sum_assignment
from scipy.spatial.distance import cosine
from scipy.sparse.csgraph import _validation  


value_cos = cosine(0.2, 0.8) * 0.5
print('\n cos value calculated using cosine', value_cos)
cost = numpy.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]])   

ls_assign = linear_sum_assignment(cost)
print("\n ls_assignment value :", ls_assign)

我在构建可执行文件时没有看到任何错误,但是当我转到 dist 目录并尝试运行可执行文件时,我收到以下错误

Traceback (most recent call last):
  File "site-packages/PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 13, in <module>
  File "/home/puneet/miniconda3/envs/nuitka/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages/pkg_resources/__init__.py", line 85, in <module>
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
[210875] Failed to execute script pyi_rth_pkgres

我不确定在构建可执行文件时是否遗漏了任何参数。任何帮助将不胜感激。

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

    感谢 Vignesh 的回复。我只是通过添加来对错误进行排序

    import pkg_resources.py2_warn
    

    在其他导入的顶部。现在可执行文件工作正常。

    【讨论】:

    • 好的,请将答案标记为已解决,以便大家知道
    【解决方案2】:

    尝试修改此注释第 15 行并在以下文件中添加以下行以进行隐藏导入 在 python 38 Windows FIXED 中,将此行添加到 Python38/Lib/site-packages/PyInstaller/hooks/hook-pkg_resources.py

    #hiddenimports = collect_submodules('pkg_resources._vendor')
    hiddenimports = collect_submodules('pkg_resources._vendor') + ['pkg_resources.py2_warn']
    

    【讨论】:

      猜你喜欢
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多