我为我的项目创建了一个 .spec 文件,PyInstaller 运行顺利。但是,在运行 .exe 时,我的加载程序出现以下问题:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "../../pyinstaller-2.0\PyInstaller\loader\iu.py", line 386, in importHook
File "../../pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
File "C:\Users\Spencer\workspace\nifty-prose-articulator\build\pyi.win32\Nifty
Prose Articulator\out00-PYZ.pyz\src.gui.main_window", line 25, in <module>
File "../../pyinstaller-2.0\PyInstaller\loader\iu.py", line 386, in importHook
File "../../pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
File "C:\Users\Spencer\workspace\nifty-prose-articulator\build\pyi.win32\Nifty
Prose Articulator\out00-PYZ.pyz\src.docx", line 15, in <module>
IOError: [Errno 2] No such file or directory: 'C:\\Users\\Spencer\\workspace\\ni
fty-prose-articulator\\build\\pyi.win32\\Nifty Prose Articulator\\out00-PYZ.pyz\
\OMMLToMathML.xsl'
除了它所指的 XSLT,我还需要在运行时加载其他 XML 文件。
这是我的 .spec 文件:
a = Analysis(['src/main.py'],
pathex=['C:\\Users\\Spencer\\workspace\\nifty-prose-articulator'],
hiddenimports=[],
hookspath=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=1,
name=os.path.join('build\\pyi.win32\\Nifty Prose Articulator', 'Nifty Prose Articulator.exe'),
debug=False,
strip=None,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas + [('OMMLToMathML.xsl', 'C:\\Users\\Spencer\\workspace\\nifty-prose-articulator\\src\\docx\\OMMLToMathML.xsl', 'DATA')] ,
Tree(os.path.abspath('src/forms/icons')),
Tree(os.path.abspath('src/docx')),
strip=None,
upx=True,
name=os.path.join('dist', 'Nifty Prose Articulator'))
app = BUNDLE(coll,
name=os.path.join('dist', 'Nifty Prose Articulator.app'))
在OMMLToMathML.xsl
里面C:\Users\Spencer\workspace\nifty-prose-articulator\src\docx
。
.spec 位于C:\Users\Spencer\workspace\nifty-prose-articulator\Nifty Prose Articulator.spec
.
我用来创建 .exe 的命令是这样的:python ../../pyinstaller-2.0/utils/Build.py "Nifty Prose Articulator.spec"
如您所见,我尝试单独添加文件并使用 a 隐式添加它Tree
(其中还有一些其他数据文件)。
我一定是做错了什么,但我一直在努力解决这个问题太久了。在此先感谢您的帮助!