gpt4 book ai didi

python - Pyinstaller:图像无法提取

转载 作者:行者123 更新时间:2023-12-01 12:23:11 25 4
gpt4 key购买 nike

我运行构建命令,一切似乎都正确构建,直到我尝试启动 exe 并弹出此消息:

Image

这是我的规范文件,我不确定为什么它似乎将文件路径与两个图像组合在一起。

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 文件的示例。 Bundling data files with 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')

错误窗口

Build -Value Error

通过对 spec 文件的这些更改,除了 failed to launch script pops 之外的所有内容都会构建启动 exe 时。如果它们与 exe 打包在一起,它们应该位于应用程序数据中的临时文件中,对吗?

谢谢!

最佳答案

来自(DOCS):

Adding Data Files:

To have data files included in the bundle, provide a list that describes the files as the value of the datas= argument to Analysis. The list of data files is a list of tuples. Each tuple has two values, both of which must be strings:

The first string specifies the file or files as they are in this system now. The second specifies the name of the folder to contain the files at run-time.

所以你的 datas 行需要是这样的:

datas=[
('C:\\Users\\test\\Downloads\\TripApp\\BennySM.ico', 'data'),
('C:\\Users\\test\\Downloads\\TripApp\\BgSM.gif', 'data'),
],

关于python - Pyinstaller:图像无法提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42164910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com