V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 3858 views
    This topic created in 2930 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
        1
    shootsoft  
       Apr 20, 2018 via iPhone
    1. 有参数可以指定打包额外的目录作为资源文件,
    2. 没办法,因为 python 本身的体积在那摆着呢。可以尝试启用 upx
    chesterzzy
        2
    chesterzzy  
       Apr 20, 2018
    多年前,我也曾尝试打包 Python 的程序为一个 exe

    最后,我放弃了

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

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