1

我正在使用 pyinstaller 和 staticx 将 Python3.6 脚本编译为静态二进制文件。我已经通过 pip 在虚拟环境(venv)中安装了所有软件包。

一切正常,直到我尝试将该行添加import networkit as nk到脚本的顶部。编译仍然有效,但是一旦我运行其他未更改的文件,我会收到以下错误:

  File "StrategicSolver.py", line 15, in <module>
    import networkit as nk
  File "<my_path>/strat_solver_env/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "networkit/__init__.py", line 50, in <module>
  File "<my_path>/strat_solver_env/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "networkit/graph.py", line 2, in <module>
  File "networkit/_NetworKit.pyx", line 6, in init networkit._NetworKit
ModuleNotFoundError: No module named 'networkit.exceptions'
[19811] Failed to execute script StrategicSolver

模块“networkit.exceptions”应该在那里(我也尝试过从源代码安装包python3 setup.py install),所以我不确定发生了什么。我没有太多从 Python 构建静态二进制文件的经验,因此将不胜感激。

4

1 回答 1

1

通过克隆存储库并注释掉 _NetworKit.pyx 中依赖于“networkit.exceptions”的任何行(见下文),我能够找到一个临时解决方法。

# from networkit.exceptions import ReducedFunctionalityWarning
.
.
.
try:
    import pandas
except:
    # warnings.warn("WARNING: module 'pandas' not found, some functionality will be restricted",
    #       ReducedFunctionalityWarning)
    pass

从那里开始,按照他们的安装指南中的描述从源代码构建。

于 2020-04-08T16:22:09.127 回答