请问用 Pyinstaller 打包怎么添加图片音频等资源呢??? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
vcent
V2EX    Python

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

  •  
  •   vcent 2018-03-18 22:43:05 +08:00 4332 次点击
    这是一个创建于 2809 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    你在打包之前能运行成功吗?如果可以,你打包的方式会不会有问题?反正图片是要跟打包之后的程序放在一起的,图片并不能打包进 exe 中
    vcent
        2
    vcent  
    OP
       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
        3
    nicevar  
       2018-03-19 12:03:41 +08:00
    这个自己写个打包脚本就行了,除了 logo 其他不相关的资源文件直接通过脚本 copy 到 dist 的程序目录下去,缺少的文件通通 copy 过去
    Hopetree
        4
    Hopetree  
       2018-03-19 13:14:53 +08:00
    @vcent 我不是用你这种命令添加的素材啊,打包方式看这个 http://www.cnblogs.com/gopythoner/p/6337543.html

    只有程序的图标是通过命令添加的,其他的图片素材都是不需要添加的,只需要把放素材的文件跟图片放在一起就行了,程序运行会自动读取素材所在的地址调用的
    vcent
        5
    vcent  
    OP
       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
        6
    zhbzhbzhbz  
       2020-04-25 13:46:02 +08:00
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1602 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 16:22 PVG 00:22 LAX 08:22 JFK 11:22
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86