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

The*_*ark 8 python pyinstaller

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

Ala*_*n L 17

使用pyi-makespec --onefile yourprogram.py生成的样本规范文件onefile模式.

https://pythonhosted.org/PyInstaller/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 )
Run Code Online (Sandbox Code Playgroud)


The*_*man 6

您可以在命令行上添加其他文件,而不用编辑规范文件:

pyinstaller --onefile --add-data <SRC;DEST or SRC:DEST> yourfile.py
Run Code Online (Sandbox Code Playgroud)

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

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

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

如果问题仍然存在,这也可能会提供一些见解:使用PyInstaller捆绑数据文件(--onefile)