推荐学习书目
› 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
hititan
V2EX  ›  Python

请问如何用 pyinstaller 打包 Python 源文件里有打开和加载某个预定的 dat 文件?

  •  
  •   hititan · Apr 20, 2018 · 4265 views
    This topic created in 3121 days ago, the information mentioned may be changed or developed.
    大侠们,你们好,小弟请教一个问题
    1:请问如何用 pyinstaller 打包 python 源文件里有打开和加载某个预定的 dat 文件?
    2:还有就是 pyinstaller 打包的文件基本超过 5M 了。请问有什么办法或者什么模块把生成的文件变小一些吗?
    6 replies  •  2018-04-21 21:01:01 +08:00
    shootsoft
    shootsoft
    Apr 20, 2018 via iPhone
    1
    1. 有参数可以指定打包额外的目录作为资源文件,
    2. 没办法,因为 python 本身的体积在那摆着呢。可以尝试启用 upx
    chesterzzy
    chesterzzy
    Apr 20, 2018
    2
    多年前,我也曾尝试打包 Python 的程序为一个 exe

    最后,我放弃了

    还是用合适的工具做合适的事吧
    omph
    omph
    Apr 21, 2018
    3
    楼上说的对,我转 PS 了
    debuggerx
    debuggerx
    Apr 21, 2018
    4
    我一般偷懒就直接把要加载的文件用相对路径,然后打包的时候加-F 选项生成一个 exe,那些文件就放 exe 同目录下,或者 exe 同目录建个 res 目录把资源文件全放进去。。5m 很大么,,我一般都用 pyqt 写小工具,mac/win 的包一般 15m+,linux 包更是将近 50m 了都
    https://github.com/debuggerx01/JSONFormat4Flutter/releases
    realism
    realism
    Apr 21, 2018 via Android
    5
    加-F 的话程序启动速度会变慢很多。而且我遇到过加-F 打包数据文件调用失败的。

    编辑. spec 文档去控制打包时包含的数据文件,参考:
    https://blog.csdn.net/u010159842/article/details/53212443
    hititan
    hititan
    OP
    Apr 21, 2018
    6
    感谢楼上的回复,真心感谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3561 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 72ms · UTC 05:16 · PVG 13:16 · LAX 21:16 · JFK 00:16
    ♥ Do have faith in what you're doing.