3

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?

Noam
  • 33
  • 3

3 Answers3

1

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

knosmos
  • 596
  • 5
  • 16
0

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

  • I think I tried pyinstaller once and it didn't work because it wasn't in PATH. Besides, pyinstaller looks more limited. cx_Freeze can work without having Python scripts inside PATH because you can make a build script and import cx_Freeze then do `python build.py build` – BlueStaggo Jan 11 '21 at 16:28
  • Thanks it almost works. With my code.exe, my links between my files don't work. I did an interface and when I push a button on it to open another one, it doesn't find the file (it says because of the path), but it worked when I tested my code.py in a terminal – Noam Jan 12 '21 at 21:48
  • I was hoping for something new here. `pyinstaller` is great for single files. My project has the usual setup: code folder, .venv folder, lots of files, etc. It's a flask server and when I run the executable it reports `ModuleNotFoundError: No module named 'flask_cors'`. Needless to say, the non-compiled version works fine. Are there any details _assumed_ in here, like `PYTHONPATH`, whether to activate the venv or where to be when you run this? Better question: did you actually try this? – Ricardo Nov 10 '21 at 14:59
0

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.

BlueStaggo
  • 121
  • 1
  • 11