我运行构建命令,一切似乎都正确构建,直到我尝试启动 exe 并弹出此消息:
这是我的规范文件,我不确定为什么它似乎将文件路径与两个图像结合在一起。
block_cipher = None
a = Analysis(['TripCalc.py'],
pathex=['C:\\Users\\test\\Downloads\\TripApp'],
binaries=[],
datas=[('C:\\Users\\test\\Downloads\\TripApp\\BennySM.ico', 'C:\\Users\\test\\Downloads\\TripApp\\BgSM.gif')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='TripCalc',
debug=False,
strip=False,
upx=True,
console=False ,
icon='C:\\Users\\test\\Downloads\\TripApp\\Benny.ico')
我尝试添加数据旁边的文件:
('Benny.ico', 'C:\\Users\\test\\Downloads\\TripApp\\BennySM.ico', 'data', 'BgSM.gif', 'C:\\Users\\test\\Downloads\\TripApp\\BgSM.gif', 'data')
但它不会与ValueError: too many values to unpack (expected 2)
.
我按照这篇文章中的示例了解如何将文件路径添加到主 python 文件。使用 PyInstaller --onefile 捆绑数据文件
我能够构建 exe 并运行它,并注释掉图像。任何帮助将非常感激。
当我收到值错误消息时,我使用以下内容设置规范文件:
block_cipher = None
a = Analysis(['TripCalc.py'],
pathex=['C:\\Users\\test\\Downloads\\TripApp'],
binaries=[],
datas=[('Benny.ico','C:\\Users\\test\\Downloads\\TripApp\\BennySM.ico','data','BgSM.gif','C:\\Users\\test\\Downloads\\TripApp\\BgSM.gif','data')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='TripCalc',
debug=False,
strip=False,
upx=True,
console=False ,
icon='C:\\Users\\test\\Downloads\\TripApp\\Benny.ico')
错误窗口
通过对规范文件的这些更改,一切都会构建,但启动脚本弹出失败启动exe时启动。如果它们与 exe 一起打包,它们应该位于应用程序数据的临时文件中,正确吗?
Thanks!