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 · 3685 次点击
    这是一个创建于 2202 天前的主题,其中的信息可能已经有所发展或是发生改变。

    毕业设计用 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   ·   我们的愿景   ·   实用小工具   ·   1149 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:01 · PVG 07:01 · LAX 16:01 · JFK 19:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.