5

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
  • maybe try pyinstaller? pyinstaller.org Commented Jan 11, 2021 at 16:15
  • stackoverflow.com/questions/35172483/… Commented Jan 11, 2021 at 16:32
  • @PeterWood Read my answer. It has more detail into how cx_Freeze works, including how to include folders inside the exe but not outside it. Commented Jan 11, 2021 at 16:34

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Pyinstaller does seem to import any python dependencies. However, you will need to move your assets folder (images etc.), keeping the same internal directory structure of the assets folder, inside the folder where your exe file is located.
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

3 Comments

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
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
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?
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.