I'm trying to deploy my python project using pyinstaller. My spec file is as follow which has dependency on sklearn:

block_cipher = None


a = Analysis(['MainUserInterface.py'],
             pathex=['..\\TSCExcelToolSet'],
             binaries=[],
             datas=[],
             hiddenimports=['sklearn'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          a.zipfiles,
          a.datas,
          [],
          name='MainUserInterface',
          debug=False,
          strip=False,
          upx=False,
          console=True)

When I try to run

pyinstaller MainUserInterface.spec

It gives this error:

SyntaxError: positional argument follows keyword argument

enter image description here

1 Answers

1
Masoud On Best Solutions

You are trying to pass exclude_binaries=True which would be translated as a positional argument and because it is passed before a.zipfiles, a.datas and [] which are keyword arguments, it would give a SyntaxError. So you need to pass it after keyword arguments. You can find more info in here.

block_cipher = None


a = Analysis(['MainUserInterface.py'],
             pathex=['..\\TSCExcelToolSet'],
             binaries=[],
             datas=[],
             hiddenimports=['sklearn'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.zipfiles,
          a.datas,
          [],
          exclude_binaries=True,
          name='MainUserInterface',
          debug=False,
          strip=False,
          upx=False,
          console=True)