Generate an executable from python project

Viewed 646

I need to generate an executable from a python project containing multiple folders and files. I tried to work with library cx_Freeze, but only worked for a single file project.

Can you tell me how to do please?

3 Answers

Running pyinstaller on your "main" python file should work, as PyInstaller automatically imports any dependencies (such as other python files) that you use.

use pyinstaller. just run pip install pyinstaller and then open the folder the file is located in with shell and run pyinstaller --onefile FILE.py where file is the name of the python file that should be run when the exe is run

Here is what you have to do:

Create a build.py file with instructions like this:

import cx_Freeze

executables = [cx_Freeze.Executable("main.py")] # The main script

cx_Freeze.setup(
    name="Platform Designer", # The name of the exe
    options={"build_exe": {
        "packages": ["pygame"], # Packages used inside your exe
        "include_files": ["data", "instructions.md"], # Files in the exe's directory
        "bin_path_includes": ["__custom_modules__"]}}, # Files to include inside the exe
    executables=executables
)

Run in command prompt:

  • python build.py build to build a exe
  • python build.py bdist_msi to build an msi installer

Make sure to remove the build and dist folders whenever you're updating your exe or msi.

Related