Python: how to specify output folders in Pyinstaller .spec file

Nickj picture Nickj · May 19, 2016 · Viewed 13.3k times · Source

I am using python 3.5 and pyinstaller version 3.1.1. I have specified a .spec file, called SCADAsync_spec.spec, as follows:

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
       )

That works fine when executed with

pyinstaller SCADAsync_spec.spec

Now that creates two large folders (dist and build) , which I would prefer to store elsewhere than in the default directory. Does anyone know how to set the location of those folders in the spec file? I'd like to keep my command line command as simple as possible, i.e. the .exe should build just by typing

pyinstaller SCADAsync_spec.spec

From the Pyinstaller manual it seems I can specify globals called 'DISTPATH' and 'workpath' to the spec file (https://pythonhosted.org/PyInstaller/spec-files.html). But I cannot really figure out how to do that.

Any help would be greatly appreciated!

Nick

Answer

Jayaprakash picture Jayaprakash · May 20, 2016

Pyinstaller spec/build/dist location paths can be configured as part of pyinstaller command. Refer below example

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