请问用 Pyinstaller 打包怎么添加图片音频等资源呢???

2018-03-18 22:43:05 +08:00
 vcent

毕业设计用 pyqt 做的一个 UI, 三个问题: 1.缺少 api-ms-win-crt-*.dll
2.添加-i 参数添加程序图标 显示错误 OSError: [Errno 22] Invalid argument 3.无法添加其他资源

那位大佬指导下,感激不尽,块交论文拉 /(ㄒoㄒ)/~~

3714 次点击
所在节点    Python
6 条回复
Hopetree
2018-03-19 09:26:46 +08:00
这是我之前用 pyqt5 写的一个爬虫程序 https://github.com/Hopetree/TMTools,这个里面就添加了 LOGO 还有其他图片效果,你自己看看

你在打包之前能运行成功吗?如果可以,你打包的方式会不会有问题?反正图片是要跟打包之后的程序放在一起的,图片并不能打包进 exe 中
vcent
2018-03-19 10:10:25 +08:00
@Hopetree 打包之前是可以的 pyinstaller --add-data=b.jpg;. --add-data=Dossier_Luffy_128px_1108222_easyicon.net.ico;. --ico=bb.jpg -w --clean Newstool.py
这是我执行的命令 然后错误不断,你打包的售后没有报错?
nicevar
2018-03-19 12:03:41 +08:00
这个自己写个打包脚本就行了,除了 logo 其他不相关的资源文件直接通过脚本 copy 到 dist 的程序目录下去,缺少的文件通通 copy 过去
Hopetree
2018-03-19 13:14:53 +08:00
@vcent 我不是用你这种命令添加的素材啊,打包方式看这个 http://www.cnblogs.com/gopythoner/p/6337543.html

只有程序的图标是通过命令添加的,其他的图片素材都是不需要添加的,只需要把放素材的文件跟图片放在一起就行了,程序运行会自动读取素材所在的地址调用的
vcent
2018-03-19 13:28:38 +08:00
@Hopetree 添加-i 选项后就是这个错误:
38771 INFO: Updating icons from ['bb.ico'] to C:\Users\ADMINI~1\AppData\Local\Temp\tmpijoxn4qa
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\Scripts\pyinstaller-script.py", line 9, in <module>
load_entry_point('PyInstaller==3.4.dev0+31785ca87', 'console_scripts', 'pyinstaller')()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\__main__.py", line 94, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\building\build_main.py", line 791, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\building\build_main.py", line 737, in build
exec(text, spec_namespace)
File "<string>", line 26, in <module>
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\building\api.py", line 420, in __init__
self.__postinit__()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\building\datastruct.py", line 161, in __postinit__
self.assemble()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\building\api.py", line 509, in assemble
icon.CopyIcons(tmpnm, self.icon)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\utils\win32\icon.py", line 177, in CopyIcons
return CopyIcons_FromIco(dstpath, [srcpath])
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\utils\win32\icon.py", line 134, in CopyIcons_FromIco
for i, f in enumerate(icons):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\pyinstaller-3.4.dev0+31785ca87-py3.5.egg\PyInstaller\utils\win32\icon.py", line 107, in __init__
file.seek(e.dwImageOffset, 0)
OSError: [Errno 22] Invalid argument


不添加 -i 可以成功打包 尽管有很多警告信息
zhbzhbzhbz
2020-04-25 13:46:02 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/439198

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX