I'm a newbie to cx_Freeze, so I tried to make an executable for a program (I'm trying to make a compiler) that uses a the module sys with this setup.py script:
from cx_Freeze import setup, Executable
base = None
executables = [Executable("main.py", base=base)]
options = {
'build_exe': {
},
}
setup(
name = "<any name>",
options = options,
version = "0.1",
description = '<any description>',
executables = executables
)
I'm using python 3.5, and when I open the generated .exe throws me this error:
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'codecs'
How i can fix that error?
You just need to update your cx_freeze version to the latest and this error will be fixed. See:
cx_Freeze: “No module named 'codecs'” Windows 10
cx_Freeze ModuleNotFoundError: No module named 'codecs'
Related
I compiled some Python scripts with cx_Freeze but compiled scripts giving me this error:
setup.py:
from cx_Freeze import setup, Executable
executables = [
Executable('USBAIO.py', base="Win32GUI", icon="Icons\\icon.ico"),
Executable('ui.py', base="Win32GUI", icon="Icons\\icon.ico"),
Executable("formatter.py", base="Win32GUI", icon="Icons\\cicon.ico"),
Executable("updater.py", base="Win32GUI", icon="Icons\\uicon.ico"),
Executable("permremove.py", base="Win32GUI", icon="Icons\\cicon.ico")
]
Packages = ["tkinter","functools", "time", "win32api",
"threading", "subprocess", "psutil", "os",
"shutil", "re", "requests", "sys", "ctypes",
"argparse", "google_drive_downloader",
"win32file", "win32con"
]
Include = ["Icons", "version.txt", "icon.ico"]
setup(
name="myapp",
options={"build_exe":{"packages":Packages,"include_files":Include}},
description = "myapp",
executables = executables
)
Python version: 3.8
Windows: 8.1 Pro WMC
cx_Freeze: 6.0b1
Well, I found the answer. The error caused by a DLL that cx_Freeze couldn't grab.
When I copy the libffi-7.dll to lib folder my application works fine.
Here is my research: research
I had the same issue. It was caused by using conda install pyqt.
Uninstalling it and reinstalling using conda install -c anaconda pyqt fixed it.
This question already has answers here:
cx_Freeze: ImportError: No module named 'PyQt5.Qt'
(3 answers)
Closed 3 years ago.
Using cx_Freeze with PyQt5, I get the following error:
ImportError: No module named 'PyQt5.Qt'
My setup.py file is as follows:
from cx_Freeze import setup, Executable
base = None
executables = [Executable("Chemistry.py", base=base)]
packages = ["idna", "sys", "pandas", "PyQt5"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "<any name>",
options = options,
version = "<any number>",
description = '<any description>',
executables = executables
)
How do I fix this error? I am using Windows OS.
Try this solution to a similar question:
Remove "PyQt5" from the packages list
Let cx_Freeze copy the whole PyQt5 directory into the lib subdirectory of the build directory. You can do that by passing a (source, destination) tuple to the include_files list, which tells cx_Freeze to copy the source (a file or a whole directory) to a destination relative to the build directory (see the cx_Freeze documentation). Set the source to os.path.dirname(PyQt5.__file__), which gives the directory of the PyQt5 package (through its __init__.py file) of your Python installation, and the destination to "lib".
Furthermore, if your application really uses pandas, you also need to add "numpy" to the packages list, see cx_Freeze not able to build msi with pandas and Creating cx_Freeze exe with Numpy for Python
Altogether, try modify your setup.py script as follows:
import os
import PyQt5
include_files = [(os.path.dirname(PyQt5.__file__), "lib")]
packages = ["idna", "sys", "numpy", "pandas"]
options = {
'build_exe': {
'include_files':include_files,
'packages':packages,
},
}
I am trying to create an executable from my Python project using cx_Freeze, but keep running into this error:
Here's my setup.py:
import cx_Freeze
import os, sys
os.environ['TCL_LIBRARY'] = "D:\\Code\\Python\\3.5.2\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "D:\\Code\\Python\\3.5.2\\tcl\\tk8.6"
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [cx_Freeze.Executable("Main.pyw", base=base)]
includes = ["tkinter"]
include_files = [r"D:\Code\Python\3.5.2\tcl\DLLs\tcl86t.dll", \
r"D:\Code\Python\3.5.2\tcl\DLLs\tk86t.dll"]
cx_Freeze.setup(
name="Test",
version = "1.0",
options={"Test.exe": {"packages":["pygame", "numpy"], "includes": includes, "include_files": include_files}},
executables = executables)
I tried putting tkinter in the "packages" list, but still get the same error. I also checked other StackOverflow posts and used parts of their setup.py code into mine, but nothing is working. I can't use PyInstaller as it doesn't support pygame and py2exe doesn't support Python 3.5. Any help would be appreciated.
Copy and Paste the files (tcl86t.dll, tk86t.dll) to the exe.win .
It worked for me.
I have a .py file that I am trying to convert into an exe. I have tried numerous tries to build this file using cx_Freeze, but I keep getting the same error every time.
I've heard that it's got something to do with cx_Freeze, so I uninstalled cx_Freeze and reinstalled it using pip install cx_freezexxxx.whl wheel, but that still didn't work. I build my exe by writing python setup.py build in command line. Here's my setup .py code.
import cx_Freeze
import sys
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\louisa\\tcl\\tk8.6"
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("filemakergui.py", base=base, icon="Treetog-I-Documents.ico")]
cx_Freeze.setup(
name = "ALT File Maker",
options = {"build_exe": {"packages":["tkinter"], "include_files":["Treetog-I-Documents.ico", "Hopstarter-Sleek-Xp-Basic-Help.ico", "Custom-Icon-Design-Flatastic-2-Success.ico"]}},
version = "0.01",
description = "ALT File Maker",
executables = executables
)
Is there anything wrong with what I've written in my setup.py file? I've been stuck on this problem for several days now. Any tips on resolving an issue like this?
Problem
I get the following error when trying to run an .exe built with cx_Freeze:
File
"C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>
from scipy.__config__ import show as show_config
ImportError: No module named 'scipy.__config__'
During handling of the above exception, another exception occurred:
...
File
"C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>
raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python interpreter.
How could I troubleshoot this?
Additional Information
Setup
Windows 7 Enterprise 64-bit
WinPython-64bit-3.5.2.3Qt5 (Python 3.5.2 64-bit)
cx_Freeze 5.0 (*)
scipy 0.18.1
(*) With pythoncom fix in the hooks.py
setup.py:
import os
import sys
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tk8.6"
base = 'Console'
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'excludes': ['gtk', 'PyQt4', 'Tkinter'],
}
}
executables = [
Executable('GUI.py', base=base)
]
setup(name='GUI',
version='0.1',
description='GUI test',
executables=executables,
options=options
)
Errors during build
None.
What else have I tried?
1) Tried to add 'includes': ['scipy.__config__'] to the setup.py.
Result: error during build ImportError: No module named 'scipy.__config__'
2) Tried to add 'packages': ['scipy'], to the setup.py.
Result: error during build ImportError: No module named 'scipy'
3) Renamed the finder.IncludePackage("scipy.lib") in the cx_Freeze/hooks.py to finder.IncludePackage("scipy._lib") as instructed in the answer of the SO Question "Cx_freeze ImportError no module named scipy" + added 'packages': ['scipy'], to the setup.py.
Result: No build-time errors. When trying to run the .exe, it gives ImportError: No module named 'scipy.spatial.ckdtree'
Tried also with 'includes': ['scipy.spatial.ckdtree'] in the setup.py, but the problem persists.
The build output has the following lines:
m scipy.spatial.cKDTree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\cKDTree.cp35-win_amd64.pyd
m scipy.spatial.ckdtree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\ckdtree.cp35-win_amd64.pyd
I think I have a solution (not the greatest but it works). Go to the scipy\spatial directory (within the build directory) and change the file from cKDTree.cp36-win_amd64.pyd to ckdtree.cp36-win_amd64.pyd.
NOTE: your file name might be slightly different depending which python version but the main thing is to use lowercase kdt in the file name.
The capital letters is the problem. It worked for me.