Create executable with python 3.7 PyQt5 and cx_Freeze but DLL Failed to load
You might be facing Issue #504 of the cx_Freeze repository. In that case, quoting a comment by marceloduarte there:
The workaround is to copy
python3.dll
to the directory where the executable was made. cx_Freeze copiespython37.dll
, but does not copypython3.dll
. Thevcruntime140.dll
may also have to be copied when it no longer exists on the system.
First try to manually copy these DLLs (you find them in the directory of your python installation containing python.exe) to the directory of your executable. If that solves the problem, you can tell cx_Freeze to do it for you by using the include_files
list of the build_exe_options
. Modify you setup script as follows:
import os
python_dir = os.path.dirname(sys.executable) # directory of your python installation
build_exe_options = {"packages": ["os", "matplotlib"],
"includes": ["PyQt5", "atexit"],
"include_files": [os.path.join(python_dir, "python3.dll"), os.path.join(python_dir, "vcruntime140.dll")],
"excludes": ["tkinter"]}
Maybe you need to copy further DLLs, such as msvcp140.dll
, or any other DLL present inside the site-packages/PyQt5
directory (including subdirectories) of your Python installation.
Compiling python project with Cx-Freeze
Use "python -m setup.py build" on cmd, that will build exe.
Example setup with extra folders:
from cx_Freeze import setup, Executable
import sys
version = "0.0.6"
build_options = {
"packages": [],
"excludes": [],
"build_exe": "X:\\builds\\",
"include_files": ["Sequence_Sample/", "icons/"],
}
base = "Win32GUI" if sys.platform == "win32" else None
executables = [Executable("MainUIController.py", base=base, targetName="pym")]
setup(
name="Python Image Macro Project",
version=version,
description="Image Based macro project.",
options={"build_exe": build_options},
executables=executables,
)
Python 3.8 and later has problem with cx_freeze 6.1 - not copying python dll.
cx_freeze 6.2 is strongly recommended if that's the case.
You'll have to clone cx_freeze and build it, then install it to use 6.2.
Related Topics
Glassfish There Is a Process Already Using the Admin Port 4848
Why This Bash Function Prints Only First Word of Whole String
Removing of Specific Line in Text File
Grep for String and Open at the Corresponding Line
How to Make .Gitignore Configurable Based on Environment Variables
How Provide Nested Mount of Overlayfs
How to Prevent an X Window from Receiving User Input
Error Cl_Device_Not_Available When Calling Clcreatecontext (Intel Core2Duo, Intel Ocl Sdk 3.0 Beta)
Why Can't Cuda's Examples Makefile Find the Cuda Libraries
How to Solve "Bash: Ls: Command Not Found"
"Echo" Output Different Answer by Sh and Bash
Hash ("#") Symbol in /Etc/Environment Causes String to Be Split
Can Someone Explain the Shell Shock Bash Code
Combine Two CSV Files Based on Common Column Using Awk or Sed
Use Bash Variable Within Slurm Sbatch Script
How to Inform Gcc to Not Use a Particular Register
Find Files in Multiple Directories Taken from List in a File