🐍 Executable Files

executable

Install module

pip install pyinstaller

For Complex Project with whole structure

  • Create a standard config file
pyinstaller bakend/main.py --onefile --windowed
  • Should create a main.spec file in the root folder

  • Ask ChatGPT what you need to add into the config file. Usually:

    • Where to find the frontend
    • Where to find the templates
    • Where to find any other files that are needed
    • Is a frontend needed?
  • Create the exe file once the config is done

pyinstaller main.spec

Path trouble shooting

⚠️ You might run into issues regarding paths. This happens because the folder structure changes once you run the program from the executable file. You might wanna create a helper function to get the paths correct in dev and in exe mode:

def resource_path(relative_path: str) -> str:
    """
    Get absolute path to resource, works for dev and for PyInstaller bundle.
    """
    base_path = getattr(sys, "_MEIPASS", os.path.abspath("."))
    return os.path.join(base_path, relative_path)

For Single File only

  • Open the terminal in the same directory as the script
pyinstaller --onefile my_file.py
  • Find the executables in the dist folder