0
我从networkx例子之一Python文件:Pyinstaller networkx模块问题
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)但我真的不知道如何正确地做到这一点。或者我应该怎么做才能解决这个问题?
我不确定这个问题是否是一个漏洞。无论如何,您可以尝试在您的参数中包含--hidden-import = networkx或--hidden-import = networkx.Graph以查看它是否有效。更多信息:http://pythonhosted.org/PyInstaller/when-things-go-wrong.html#listing-hidden-imports。 – Repiklis
在spec文件中使用正确的隐藏导入或使用--hidden-import作为参数后@Repiklis出现同样的错误。 –