Can't build .exe using Pyinstaller

Viewed 337

I have 2 files, One is Main.py other one is Autoe.ui, I want both as a single .exe I tried

pyinstaller -w --add-data="Autoe.ui;." Main.py

This works just fine, but it creates lot of other files as well, I wanted just a single exe, So I tried this

pyinstaller.exe -w --onefile --add-data="Autoe.ui;." Main.py

This creates a single .exe but it won't run, I get a pop-up saying "Failed to execute script Main"

1 Answers

I had a similar problem with the Kivy app. In my case it was a kv file, not a ui. Maybe what I did will help you. In the folder with the * .py file I ran the command:

pyinstaller --onefile -y --clean --windowed --icon=someicon.ico main.py

The main.spec file appeared in the folder. I have edited it.

# -*- mode: python ; coding: utf-8 -*-
block_cipher = None

a = Analysis(["main.py"],
             pathex=["C:\\Users\\underground\\Desktop\\gdc"], #<<<<<<<path to folder of your app
             binaries=[]
             datas=[],
             hiddenimports=[],
             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)
             
a.datas += [('gdc.kv', 'C:\\Users\\underground\\Desktop\\gdc\\gdc.kv', 'DATA')]  #<<<< I added kv file to a.datas
excluded_binaries = ['VCRUNTIME140.dll']                        #<<<< I disabled this library because my app won't start on win10
a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries])

exe = EXE(pyz, Tree('C:\\Users\\underground\\Desktop\\gdc\\Data','Data'), 
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=False , icon='ikona.ico')

When I edited the spec file, I ran pyintaller again but gave the spec file instead of the * .py file.

pyinstaller main.spec

...that's all. You can also try the GUI version - auto-py-to-exe instead of pyinstaller.

Related