Cx-freeze cannot load pyglet.media module - python-3.x

In my python(3.4) file, I used pyglet.media module. Now I build an exe using cx_Freeze following structure of this question.My setup.py is :
from cx_Freeze import setup, Executable
setup(
name = "program",
version = "1.0",
description = "test",
executables = [Executable("program.py")])
When I run the exe, I receive this error:
ImportError: No module named 'pyglet.media'
I add import pygletat the beginning of setup.py but still doesnt work.
How can I force importing pyglet.media module beside exe file?
I know there is a similar question in this link and this link, but they are either old or there is no working answer.

You should include pyglet package as options.
build_exe_options = {"packages": ["pyglet"]}
from cx_Freeze import setup, Executable
setup(
name = "program",
version = "1.0",
description = "test",
options = {"build_exe":build_exe_options},
executables = [Executable("program.py")])

Related

No module named 'tkinter' when trying to create exe file

I wrote some files in python and want to create an exe file. To do it with cx_freeze I create a setup.py file like that:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"includes": ["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 = "LSR",
version = "0.1",
description = "",
options = {"build_exe": build_exe_options},
executables = [Executable("LS-R.py", base = base)])
then I write in the cmd :
python setup.py build
and I get this error:
error during GetDependentFiles() of "c:\users\appdata\local\programs\python\python36\dlls\tk86t.dll": (0, 'The system cannot find the file specified', 'c:\users\appdata\local\programs\python\python36\dlls\tk86t.dll', 2, None)
copying C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pywin32_system32\pywintypes36.dll -> build\exe.win-amd64-3.6\lib\pywintypes36.dll
copying C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\pywin32_system32\pythoncom36.dll -> build\exe.win-amd64-3.6\lib\pythoncom36.dll
exe file created , but when I try open it I get this message :
ModuleNotFoundError:No module named 'tkinter'
someone know what is the problem? and what should I do to fix it? (I'm working in Windows OS)
Its Quite simple use;
pip install auto-py-to-exe
It will give you A GUI and is as simple as it gets. It is based on
Pyinstaller, cx-freeze, etc
See PyPI.
I was having the same problems even in Pyinstaller but this is the easiest way without any errors and is the most Effective way.
After Installation in cmd type
auto-py-to-exe
This will open a new Browser window with a beautiful and easy to use GUI.
It works for Tkinter well as I have used to to create like 50 Tkinter .exe files.
I made a program for activating windows in Tkinter with this;
See: https://drive.google.com/file/d/1RKLIlGcrra1pC5MyaPWrlQa1tW25Wc_q/view
I hope this makes your job quite easy.

error after compiling .py to .exe

when I compile a program from .py into .exe and open .exe, this error appears
when I compile a program from .py into .exe and open .exe, this error appears
from cx_Freeze import setup, Executable
setup(
name = "Diophantine equantion",
version = "1.0",
description = "Diophantine equantion",
executables = [Executable("Diofant.py", base='Win32GUI')]
)
Just add options = {'build_exe': {'includes': ['numpy.core._methods']}} to your setup.

Comand promp closes instantly with cx_Freeze and requests module

Im trying to build a simple executable file from python using cx_Freeze, but the script uses request module. As many many other threads say, it seems to be a problem involving cx_freeze and requests module, something about the path of the files that requests need to run and cx_freeze changes or doesnt import when freezing.
The build process works just fine, but when the exe is created, if i try to open it, a comand promp shows for a fraction of a second and then closes, displaying something so quickly that i dont have time to read or even snapshot, but it doesnt have the structure of an error message.
I think the problem is probably the thing about paths, but i dont know how to solve it, and everything i've found in internet haven't worked for me.
Please help.
Here is a copy of the test file named "prueba2.py"
import requests
print("hi")
print(requests)
input()
and the setup.py
from cx_Freeze import setup, Executable
import sys
import os
import requests.certs
base = None
executables = [Executable("prueba2.py", base=base)]
packages = ["idna"]
options = {
'build_exe': {
'packages': packages,
'include_files': [os.path.join(sys.base_prefix, 'DLLs','sqlite3.dll'),
(requests.certs.where(), 'cacert.pem')]
},
}
setup(
name="<any name>",
options=options,
requires=["requests"],
version="<any number>",
description='<any description>',
executables=executables
)
It seems there are some dependencies for cx_freeze in new versions of the module
try modifying the main file like this:
import requests
from multiprocessing import Queue
print("hi")
print(requests)
input()
and setup.py as :
from cx_Freeze import setup, Executable
import sys
import os
import requests.certs
base = None
executables = [Executable("prueba2.py", base=base)]
packages = ["idna"]
options = {
'build_exe': {
'packages': packages,
'include_files': [os.path.join(sys.base_prefix, 'DLLs', 'sqlite3.dll'),
(requests.certs.where(), 'cacert.pem')]
},
}
setup(
name="name",
options=options,
requires=["requests"],
version="1",
description='test',
executables=executables
)

What DLL's I have to load for Gobject in cx_freeze

I have a little problem with cx_freeze and hoping one of you can help me. I have searched trough this wonderfull forum but I can't find the answer.
I have used cx_freeze before with python 3.3 and ktinker and that worked flawless.
Now I made a little tool with a bit more complex gui and tried Glade.
Building the gui with Glade works perfect for me and on Linux and Windows 7 the application I have made works fine (in python interpreter).
When I run python setup.py bdist_msi I don't see any faults but when I try to run the exe in windows I get this error window:
(I can't post images jet)
The last 4 lines are:
_load_backward_compatible
File "ExtentionLoader_gi_gi.py", line 22, in <module
File "ExtentionLoader_gi_gi.py", line 14, in_bootstrap_
ImportError: DLL load failed: The specified module could not be found
I don't use any plugins, exotic imports so the dll's I have to load are only the dll's for Gobject. The setup file I have made from an example on this forum. For my ktinker app I did not have to import any dll.
Finally the question: Is there a list of dll's somewhere that tells me what dll's I have to add?
And is there something wrong with my setup.py?
The code is nothing special but if you want to check it: https://github.com/EddenBeer/CodeGenerator
The imports in Python:
import csv import sys import datetime
from gi.repository import Gtk
Installed on Windows 7:
Python-3.4.2
cx_Freeze-4.3.3.win32-py3.4
pygi-aio-3.14.0_rev6-setup
Setup.py:
import os, site, sys
from cx_Freeze import setup, Executable
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gnome")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-3-0.dll',
'libgdk-3-0.dll',
'libatk-1.0-0.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libjpeg-8.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll',
'libgnutls-26.dll',
'libgcrypt-11.dll',
'libp11-kit-0.dll'
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_folder = 'glade'
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_folder, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("CodeGenerator.py",
base=base
)
]
buildOptions = dict(
compressed = False,
includes = ["gi", "csv", "datetime",],
packages = ["gi"],
include_files = include_files
)
setup(
name = "Code Generator",
author = "Ed den Beer",
version = "1.0",
description = "Generating copy instructions for RsLogix5000 out of a list with tags in a CSV file",
options = dict(build_exe = buildOptions),
executables = executables
)
My problem is solved.
Looking for an answer if found a utility called ListDlls.exe.
In this link is explaned how to use it:
https://bitbucket.org/anthony_tuininga/cx_freeze/issue/92/pygi-and-cx_freeze-error

cx_freeze QtWebKit import error

My cx_freeze build was working correctly until I added one QWebView element into window. This means I should import QtWebKit, right? On Linux everything works perfectly. On Windows, if I run main.py file everything works perfectly.
If I freeze it into an .exe, this is the error I get . This is my install.py file:
from cx_Freeze import setup, Executable
includes=["re","PyQt4.QtWebKit"]
exe = Executable(
script="main.pyw",
base="Win32GUI",
targetName = "LEX.exe"
)
setup(
name = "blabla",
version = "1.3",
description = "My application",
options = {"build_exe": {"includes":includes}},
executables = [exe]
)
I am building it on x64 Windows 7, but with x86 versions of PyQt4 and Python3.2 x86. Before that QWebView element there were no problems at all.
Upgrading to cx_freeze 4.3 and editing the imports did the trick. Imports are now like this:
from PyQt4.QtNetwork import *
from PyQt4.QtWebKit import QWebView,QWebPage
You should not add imports (and possibly pollute your namespace) just to have cx_Freeze recognize the dependency.
Rather add PyQt4.QtNetwork to your "includes" list as you did with PyQt4.QtWebKit.
You can also include all modules of a package by using the "packages" option. That is, "packages" is for whole packages what "includes" is for modules.

Resources