【问题标题】:Using --onefile with a .spec in PyInstaller在 PyInstaller 中使用带有 .spec 的 --onefile
【发布时间】:2017-11-06 18:22:14
【问题描述】:

我正在使用 PyInstaller 使用 .spec 文件“编译”一个程序。我正在使用 .spec 文件,因为我需要在程序中包含一个额外的文件。当我尝试做PyInstaller --onefile Prog.spec 时,它仍然会在dist 中创建一个文件夹,其中所有文件都是分开的,而不是像我期望的那样创建一个文件。如果我做PyInstaller --onefile Prog.py,那么它确实会在dist 中创建一个.exe 文件,这就是我想要的。使用 .spec 文件时我需要做些什么特别的事情吗?

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

    使用pyi-makespec --onefile yourprogram.py 为 onefile 模式生成示例规范文件。

    https://pyinstaller.readthedocs.io/en/stable/man/pyi-makespec.html


    没有COLLECT调用,EXE调用不同。示例:

    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              name='main',
              debug=False,
              strip=False,
              upx=True,
              runtime_tmpdir=None,
              console=True )
    

    【讨论】:

      【解决方案2】:

      您可以在命令行中添加额外的文件,而不是编辑规范文件:

      pyinstaller --onefile --add-data <SRC;DEST or SRC:DEST> yourfile.py
      

      否则,请确保在 spec 文件中没有收集步骤:

      “在单文件模式下,不调用 COLLECT,EXE 实例接收所有脚本、模块和二进制文件。”

      https://pyinstaller.readthedocs.io/en/stable/usage.html 了解有关命令行标志的更多信息。

      如果问题仍然存在,这也可能提供一些见解:Bundling data files with PyInstaller (--onefile)

      【讨论】:

        猜你喜欢
        • 2016-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-24
        • 2019-01-04
        • 1970-01-01
        • 1970-01-01
        • 2011-12-02
        相关资源
        最近更新 更多