ModuleNotFoundError error from .pyd file - python

I had to to transform a module from .py to .pyd. I did it with Cython. I tested after the project, and everything worked fine. When I created a build with cx_Freeze, that .pyd module created problems. I can't understand why after building I get this ModuleNotFoundError.
File "tooth_comp.pyx", line 13, in int
src.graphics_dental_components.tooth_comp
ModuleNotFoundError: No module named 'graphics_utils.effects'
My setup script:
import sys
from cx_Freeze import setup, Executable
packages = []
excludes = []
include_files = ["assets", "views"]
build_exe_options = {"packages": packages, "excludes": excludes, "include_files": include_files}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "MyApp",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)])

The reason for the error message is because the application cannot find the extension.
Try adding graphics_utils.effects to the packages list then try recompiling.
If that does not work you could also try coping the module in the build folder manually.

Related

Unable to compile with cx_freeze and PySide2

I have a python program I'm trying to compile with cx_freeze. The GUI I'm using is PySide2.
I've tried including PySide2, here is excluding it, but I keep getting the same error. Below is my setup.py code
from cx_Freeze import setup, Executable
import sys
includefiles = ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py']
includes = ["idna.idnadata", "atexit"]
excludes = ["PySide2"]
import os
os.environ['TCL_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\pimat\AppData\Local\Programs\Python\Python36\tcl\tk8.6'
setup(name = "Simulation",
version = "0.2",
description = "Optimization Simulator",
options = {'build_exe':{'includes':includes,'excludes':excludes,'include_files':includefiles}},
executables = [Executable("main.py")])
The program compiles fine, but when running the exe, I get the following error:
"ModuleNotFoundError: No module named 'PySide2'"
So the error was that I had installed cx_freeze with python 3.6, but all of my packages were in a python 3.7 folder. I simply copied and pasted into the 3.6 folder and changed the code a bit, and the exe works great.
from cx_Freeze import setup, Executable
import sys
# dependencies
build_exe_options = {
"packages": ["os", "sys", "re", "idna.idnadata", "atexit", "PySide2.QtCore", "PySide2.QtWidgets", "PySide2.QtUiTools", "PySide2.QtQuick", "PySide2.QtQml", "PySide2.QtGui", "shiboken2"],
"include_files": ['README.md', 'debug.log','tcl86t.dll', 'tk86t.dll', 'field.jpg', 'inputClass.py', 'mainfile.qml', 'MyTabView.qml', 'PlayerSelection.qml', 'selectedPlayers.py', 'Settings.qml', 'SimOutput.qml', 'simulationOutput.py',
],
"excludes": ["Tkinter", "Tkconstants", "tcl", ],
"build_exe": "build",
#"icon": "./example/Resources/Icons/monitor.ico"
}
executable = [
Executable("main.py",
base="Win32GUI",
targetName="Simulation.exe"
)
]
setup(name = "Simulation",
version = "0.2",
description = "Simulator",
options={"build_exe": build_exe_options},
executables=executable
)
T'was a dumb mistake, but I've made worse

Getting "ImportError: DLL load failed: The specified module could not be found" when using cx_Freeze even with tcl86t.dll and tk86t.dll added in

I am trying to convert a .py file to .exe using cx_Freeze 5.1.1., but an ImportError: DLL load failed pops up every time I try to run the file. Based on the suggested solutions here and here, I added tcl86t.dll and tk86t.dll to the list of included files. They appear in the build folder, but the error message keeps popping up.
Here is my setup.py:
import sys
import os
from cx_Freeze import setup, Executable
os.environ["TCL_LIBRARY"] = r"C:/Users/Name/AppData/Local/Programs/Python/Python36-32/tcl/tcl8.6"
os.environ["TK_LIBRARY"] = r"C:/Users/Name/AppData/Local/Programs/Python/Python36-32/tcl/tk8.6"
base = "Win32GUI" if sys.platform=="win32" else None
build_exe_options = {"packages": ["winsound", "random", "time", "tkinter", "math"],
"include_files": ['tcl86t.dll',
'tk86t.dll']}
setup(
name = "Game",
author = "Name",
description = "game description",
options = {"build_exe": build_exe_options},
executables = [Executable("game.py", base=base)]
)
I'm using Python 3.6.3 and Windows 10. Any help would be greatly appreciated!
In cx_Freeze version 5.1.1, the included modules are in a subdirectory lib of the build directory. The tcl86t.dll and tk86t.dll DLLs apparently need to be moved there as well.
You can do this with the following modification of your setup.py script:
build_exe_options = {"packages": ["winsound", "random", "time", "tkinter", "math"],
"include_files": [('tcl86t.dll', os.path.join('lib', 'tcl86t.dll')),
('tk86t.dll', os.path.join('lib', 'tk86t.dll'))]}

Python3 cx_Freeze error 'no module named gi'

I am trying to use cx_Freeze with a python3 programme I have written which uses Gtk. I ran cxfreeze-quickstart and then python setup.py build using the setup.py file created for me. However, I got this error: ImportError: No module named 'gi'.
This is my setup.py file:
from cx_Freeze import setup, Executable
buildOptions = dict(packages = [], excludes = [])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('bio_gtk_programme.py', base=base)
]
setup(name='Bio Programme',
version = '1.0',
description = 'Bio Gtk',
options = dict(build_exe = buildOptions),
executables = executables)
Do I need to include 'gi' in packages = [] or add anything to the hooks.py file?
I've also tried this with py2exe on Windows, and I get the same ImportError...

How to use cx_freeze with pyautoit?

I want to create a cx_freeze executable from my windows application that use "pyautoit" module.
pip install -U pyautoit
This is my example code:
main.py
import autoit
autoit.run("notepad.exe")
autoit.win_wait_active("[CLASS:Notepad]", 3)
autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}")
autoit.win_close("[CLASS:Notepad]")
autoit.control_click("[Class:#32770]", "Button2")
setup.py
import sys
from cx_Freeze import setup, Executable
build_exe_options = {
"packages": ["autoit"],
"excludes": []
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "AutoItSample",
version = "0.1",
description = "Automate Notepad Editor",
options = {"build_exe": build_exe_options},
executables = [Executable("main.py", base=base)],
)
And I created the build with this command inside my project folder.
python setup.py build
This module use a .dll file included inside the module folder.
autoit
lib
AutoItX3.dll
autoit.py
...
But cx_freeze doesn't include this .dll in the library.zip archive.
I tried to include the lib folder manually inside the library.zip archive.
But I've got the same error.
http://pix.toile-libre.org/upload/original/1428496271.png
What should I do to make it work?
Try using the zip_includes option in your setup.py file:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {
"packages": ["autoit"],
"excludes": [],
"zip_includes": ['AutoITX3.dll']
}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "AutoItSample",
version = "0.1",
description = "Automate Notepad Editor",
options = {"build_exe": build_exe_options},
executables = [Executable("main.py", base=base)],
)

Python cx_freeze setup script not working

I have a python script that I'd like to freeze. I made the cx_freeze script, and ran it. The .exe works well, but in the frozen script I open a .html file. When the file opens the webbrowser gives me the error "File not found: Firefox cannot find the file at /c:/blah/blah/blah/somefile.html"
As I understand it, this is because cx_freeze is confusing my OS between linux and Windows. However, I'm not sure this is it because I have the code
if sys.platform == "win32":
base = "Win32GUI"
In my setup file. Does anyone know what's going on?
My entire setup file is
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "someexe",
version = "0.1",
description = "someexe description",
options = {"build_exe": build_exe_options},
executables = [Executable("someexe.py", base=base)])
copied from the cx_freeze distutils page and edited to fit my needs.
Instead of using os.chdir('C:/path/to/dir'), you should be using os.chdir('C:\path\to\dir'). It's an error in your script, not your cx_freeze setup file.

Categories