簡體   English   中英

在 PyInstaller 中使用帶有 .spec 的 --onefile

[英]Using --onefile with a .spec in PyInstaller

我正在使用 PyInstaller 使用 .spec 文件“編譯”一個程序。 我正在使用 .spec 文件,因為我需要在程序中包含一個額外的文件。 當我嘗試執行PyInstaller --onefile Prog.spec ,它仍然在dist創建一個文件夾,其中所有文件都是分開的,而不是像我期望的那樣創建單個文件。 如果我執行PyInstaller --onefile Prog.py那么它會在dist中創建一個 .exe 文件,這就是我想要的。 使用 .spec 文件時我需要做什么特別的事情嗎?

使用pyi-makespec --onefile yourprogram.pypyi-makespec --onefile yourprogram.py生成示例規范文件。

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 )

您可以在命令行上添加額外的文件,而不是編輯規范文件:

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

否則,請確保在規范文件中沒有收集步驟:

“在單文件模式下,不調用 COLLECT,EXE 實例接收所有腳本、模塊和二進制文件。”

https://pyinstaller.readthedocs.io/en/stable/usage.html有關命令行標志的更多信息。

如果問題仍然存在,這也可以提供一些見解: Bundling data files with PyInstaller (--onefile)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM