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?
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?
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
python build.py buildpyinstaller 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?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 exepython build.py bdist_msi to build an msi installerMake sure to remove the build and dist folders whenever you're updating your exe or msi.