Python:如何在 Pyinstaller .spec 文件中指定输出文件夹

标签 python pyinstaller

我使用的是 python 3.5 和 pyinstaller 版本 3.1.1。我指定了一个名为 SCADAsync_spec.spec 的 .spec 文件,如下所示:

block_cipher = None

a = Analysis(['SCADAsync.py'],
             pathex=['C:\\repo\\analysis\\trunk\\source\\python\\functions', 'C:\\repo\\analysis\\trunk\\source\\python\\Executables'],
             binaries=None,
             datas=[('figs\\ROMO_icon.ico','figs'),('figs\\OpenFile2.gif','figs'),('figs\\ROMOWind_Logo2015_CMYK.png','figs')],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='SCADAsync',
          debug=True,
          strip=False,
          upx=True,
          console=True
       )

执行时效果很好
pyinstaller SCADAsync_spec.spec

现在创建了两个大文件夹(dist 和 build),我更愿意将它们存储在其他地方而不是默认目录中。有谁知道如何在规范文件中设置这些文件夹的位置?我想让我的命令行命令尽可能简单,即 .exe 应该只需键入

pyinstaller SCADAsync_spec.spec

从 Pyinstaller 手册看来,我可以为规范文件 (https://pythonhosted.org/PyInstaller/spec-files.html) 指定名为“DISTPATH”和“workpath”的全局变量。但我真的不知道该怎么做。

如有任何帮助,我们将不胜感激!

尼克

最佳答案

Pyinstaller spec/build/dist 位置路径可以配置为 pyinstaller 命令的一部分。引用下面的例子

pyinstaller --specpath /opt/bk/spec --distpath /opt/bk/dist --workpath /opt/bk/build testscript.py

关于Python:如何在 Pyinstaller .spec 文件中指定输出文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37319911/

相关文章:

python - pyinstaller在exe文件中添加包含图像的文件夹

python - 如何将静态位图帧从 GIF 提供给 wxpython 形状帧

python - 选择哪个 python re 模块来翻译 perl 正则表达式

python - 在 h2o AutoML 上检索 h2o AutoML 的交叉验证性能 (AUC) for holdout dataset

python - Numpy 类型错误

python - 导入错误 : No module named FileDialog - after PyInstaller

python - 如何从列表中删除第一项?

python - 使用pyinstaller创建可执行文件时出错

python - PyInstaller/Py2exe - 在单文件编译中包含带有第三方脚本的 os.system 调用

python - Pyinstaller 设置图标不会改变