Pyinstaller networkx 模块问题

Pyinstaller networkx module issue

我有一个来自 networkx 示例的 python 文件:

from networkx import Graph

G=Graph()
G.add_node("spam")
G.add_edge(1,2)
print(list(G.nodes()))
print(list(G.edges()))

现在我想使用pyinstaller构建bin文件

pyinstaller --debug --onedir nx.py

构建后 运行 nx.exe 我在 cmd 中收到此错误:

PyInstaller Bootloader 3.x
LOADER: executable is C:\Users\XRP836\Desktop\MeshSim\ex\dist\nx\nx.exe
LOADER: homepath is C:\Users\XRP836\Desktop\MeshSim\ex\dist\nx
LOADER: _MEIPASS2 is NULL
LOADER: archivename is C:\Users\XRP836\Desktop\MeshSim\ex\dist\nx\nx.exe
LOADER: No need to extract files to run; setting extractionpath to homepath
LOADER: SetDllDirectory(C:\Users\XRP836\Desktop\MeshSim\ex\dist\nx)
LOADER: Already in the child - running user's code.
LOADER: Python library: C:\Users\XRP836\Desktop\MeshSim\ex\dist\nx\python27.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: sys.prefix is C:\Users\XRP836\Desktop\MeshSim\ex\dist\nx
LOADER: Setting runtime options
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:\Users\XRP836\Desktop\MeshSim\ex\dist\nx
LOADER: Setting sys.argv
LOADER: setting sys._MEIPASS
LOADER: importing modules from CArchive
LOADER: extracted struct
LOADER: callfunction returned...
LOADER: extracted pyimod01_os_path
LOADER: callfunction returned...
LOADER: extracted pyimod02_archive
LOADER: callfunction returned...
LOADER: extracted pyimod03_importers
LOADER: callfunction returned...
LOADER: Installing PYZ archive with Python modules.
LOADER: PYZ archive: out00-PYZ.pyz
LOADER: Running pyiboot01_bootstrap.py
LOADER: Running pyi_rth_pkgres.py
Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 11, in <module>
  File "c:\users\xrp836\appdata\local\temp\pip-build-hppbcz\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line
389, in load_module
  File "site-packages\pkg_resources\__init__.py", line 2958, in <module>
  File "site-packages\pkg_resources\__init__.py", line 2944, in _call_aside
  File "site-packages\pkg_resources\__init__.py", line 2986, in _initialize_master_working_set
UnboundLocalError: local variable 'dist' referenced before assignment
Failed to execute script pyi_rth_pkgres
LOADER: OK.
LOADER: Cleaning up Python interpreter.

据我所知,我需要为 pyinstaller 创建挂钩文件(hook-networkx.py),但我真的不知道如何正确地做。或者我应该怎么做才能解决这个问题?

问题已通过将pyinstaller降级到3.1版本解决。