Pyinstaller:图像无法提取 [英] Pyinstaller: Images fail to extract

查看:88
本文介绍了Pyinstaller:图像无法提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

block_cipher = 无a = Analysis(['TripCalc.py'],pathex=['C:\\Users\\test\\Downloads\\TripApp'],二进制文件=[],datas=[('C:\\Users\\test\\Downloads\\TripApp\\BennySM.ico', 'C:\\Users\\test\\Downloads\\TripApp\\BgSM.gif')],隐藏进口=[],钩子路径=[],runtime_hooks=[],排除=[],win_no_prefer_redirects=假,win_private_assemblies=假,密码=block_cipher)pyz = PYZ(a.pure, a.zipped_data,密码=block_cipher)exe = EXE(pyz,a. 脚本,a.二进制文件,a.zip 文件,a.数据,name='TripCalc',调试=假,条=假,upx=真,控制台=假,icon='C:\\Users\\test\\Downloads\\TripApp\\Benny.ico')

我尝试在数据旁边添加文件:

('Benny.ico', 'C:\\Users\\test\\Downloads\\TripApp\\BennySM.ico', 'data', 'BgSM.gif', 'C:\\用户\\测试\\下载\\TripApp\\BgSM.gif', '数据')

但它不会用 ValueError: too many values to unpack (expected 2) 构建.

我遵循了这篇文章中关于如何将文件路径添加到主 python 文件的示例. 启动 exe 时启动.如果它们与 exe 打包在一起,它们应该位于应用程序数据中的临时文件中吗?

谢谢!

解决方案

来自 (DOCS):

<块引用>

添加数据文件:

要在包中包含数据文件,请提供一个列表,将文件描述为 Analysisdatas= 参数的值.数据文件列表是一个元组列表.每个元组有两个值,都必须是字符串:

第一个字符串指定当前系统中的一个或多个文件.第二个指定在运行时包含文件的文件夹的名称.

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

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

I run the build command and everything appears to build correctly until I try to launch the exe and this message pops up:

Here is my spec file, I am not sure why it appears to be combing the file path with both images.

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')

I tried adding the files beside datas:

('Benny.ico', 'C:\\Users\\test\\Downloads\\TripApp\\BennySM.ico', 'data', 'BgSM.gif', 'C:\\Users\\test\\Downloads\\TripApp\\BgSM.gif', 'data')

But it would not build with the ValueError: too many values to unpack (expected 2).

I followed the example from this post on how to add the file path to the main python file. Bundling data files with PyInstaller --onefile

I am able to build the exe and run it with the images commented out. Any help would be much appreciated.

When I get the Value Error message I setup the spec file with the following:

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')

Error window

With those changes to the spec file everything builds but the failed to launch script pops up when launching the exe. If they got packed with the exe they should be locationed in the temp file in app data correct?

Thanks!

解决方案

From the (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.

So your datas line will need to be something like:

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

这篇关于Pyinstaller:图像无法提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆