0

i have this .spec file that i use to convert my python project into an executable, the command works just fine however the command generates a folder with a lot of files (the executable among them) but i want it to generate a standalone executable file

Command:

pyinstaller main.spec

main.spec file:

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

a = Analysis(
    ['main.py', 'ui_interface.py', 'utilities.py', 'data.py'],
    pathex=[],
    binaries=[],
    datas=[('MainMenu.ui', '.'), ('style.json', '.'), ('resources_rc.py', '.')],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    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,
    name='D&PO UIB',  # Set the name of the executable to "D&PO UIB"
    debug=True,  # Enable debug output
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=False,  # Set console to False to remove the console window
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    onefile=True,  # Generate a single executable file  # Add the path to your icon file
)

coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],  # Include the upx_exclude parameter with an empty list
    name='D&PO UIB',  # Set the name of the executable to "D&PO UIB"
)

As you can see the onefile parameter is set to True but still nothing, i tried changing a lot of parameters and i tried a lot of methods that chatgbt requested but none of them work, it keeps generating a folder with plenty of files.

Fares
  • 1

1 Answers1

1

Simply get rid of your

COLLECT(...)

statement. That should do the trick.

See also here https://pyinstaller.org/en/stable/spec-files.html#spec-file-operation

"An instance of COLLECT creates the output folder from all the other parts. In one-file mode, there is no call to COLLECT, and the EXE instance receives all of the scripts, modules and binaries."

EDIT:

My guess: Set this line to False (or simply delete it) to keep the binaries

exclude_binaries=False

Because you exclude all binariers, there is no python39.dll on the path.

EDIT 2:

The problem is that you must include the binaries to the .exe as well via

a.binaries

I attached the exe part below. I also tested this with an easy executable on my machine and it worked. When i skipped the a.binaries add or set the exlude binaries to True, i got the same error as you.

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    exclude_binaries=False,
    name='D&PO UIB',  # Set the name of the executable to "D&PO UIB"
    debug=True,  # Enable debug output
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=False,  # Set console to False to remove the console window
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    onefile=True,  # Generate a single executable file  # Add the path to your icon file
)
stranger0612
  • 301
  • 1
  • 2
  • 12
  • i did as you instructed and removed the COLLECT(...) but now i get a different problem, when i try to build the app using ```pyinstaller main.spec``` i get an empty dist folder and a build folder with a bunch of files among them is the executable but it does not work, it gives me this error ```Fatal error detected Error loading Python DLL '*path to my build folder*\main\python39.dll' LoadLibrary: The specified module could not be found.``` – Fares Jul 26 '23 at 16:24
  • Edited my answer. – stranger0612 Jul 27 '23 at 05:00
  • i tried that but the problem still persists, i have also went to github to ask the maintainers of the pyinstaller module but still no solution can be found :/ – Fares Jul 29 '23 at 17:27
  • Updated my answer. Sorry, i forgot to mention that we need to add a.binaries as well... Hope my edit fixes your problem, now? – stranger0612 Jul 31 '23 at 06:10
  • i am still facing the same problem, the program that it is built still has a bad interface and the buttons do not work – Fares Aug 02 '23 at 01:56
  • Sorry to hear. But why still facing the same problem? That's a new one? You initial question was how to built a onefile executable and afterwards there was the dll missing problem which got both fixed by my answer? The new one with your compiled program not working as expected is a new one. Hard to tell why you got this behavior with only seeing your spec file or even knowing which frontend you are using. I guess your Python project works, when not compiled? Also is the the added data handled properly? See also this https://stackoverflow.com/q/22472124/7990773 – stranger0612 Aug 02 '23 at 05:03