Running Executable made with cx_Freeze giving traceback error - python

Here is my setup.py file for cx_Freeze
import sys
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r"C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\tcl\tk8.6"
build_exe_options = {"packages":["os"], "includes" : ["tkinter"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name='APS West Email Generator',
version='1.0',
description='Auto generates Alarm notification emails. And maybe more in the future.',
options = {"build_exe": build_exe_options},
executables = [Executable("Tool_EmailGenerator.py", base=base)])
The executable is made with no errors. But when I try to run it I get the following window:
title: cx_Freeze: Python error in main script
contents:
Traceback(most recent call last):
file
"c:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\cx_Freeze\initscripts__startup__.py",line12,in import(name+ "init")
file
"c:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\cx_Freeze\initscripts\Console.py",line 21, in scriptModule=import(moduleName)
File "Tool_EmailGenerator.py", line 2, in
File
"c:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\tkinter__init__.py", line 35, in
import_tkinter #if this fails your python may not be configured for Tk
ImportError: DLL load failed: The specified module could not be found.
tkinter works when I run the py file pre-cx_Freeze. I've searched the internet and tried various suggestions. nothings worked so far. I'm not sure whats causing this.

managed to fix this issue.
Instead of doing:
"includes" : ["tkinter"],
I added tkinter to the packages.
so: "packages":["os", "tkinter"]
that seemed to work

Related

ImportError When Using cx_Freeze On a Script The Includes ffpyplayer

I successfully froze a Python 3.6 script with cx_Freeze v5.1.1. Then I added a new capability to the script by adding MediaPlayer from the ffpyplayer package and the script works perfectly. But when I freeze the new script, I receive an error "from ffpyplayer.player import MediaPlayer ImportError: DLL load failed: The specified module could not be found."
The import statement in my application script is
from ffpyplayer.player import MediaPlayer
From other posts, I have tried adding both ffpyplayer and ffpyplayer.player to the packages statement in the cx_Freeze setup.py script (in separate attempts) to fix the problem. I also tried adding player.cp36-win_amd64.pyd to the include statement in setup.py, but I still got the same error message.
cx_Freeze copied all ffpyplayer files from site-packages into the exe.win-amd64-3.6\lib\ffpyplayer except the __pycache__ folder containing __init__.cpython-36.pyc. However, manually adding this folder to exe.win-amd64-3.6\lib\ffpyplayer\ and to exe.win-amd64-3.6\lib\ffpyplayer\player\did not fix the issue (same error message).
Here is a minimal version of the setup.py file that cx_Freeze uses:
from cx_Freeze import setup, Executable
d = "C:\\Users\\Slalo_000\\Dropbox\\Python36Scripts\\AddtoBuild\\"
exe=Executable(script="VSWv300.py", base = "Win32GUI", icon = d + "VSWiconLarge.ico")
includes=[]
excludes=[]
packages=["numpy", "cv2", "ffpyplayer"]
setup(
version = "2.0.0.0",
description = "appName",
author = "me",
author_email = "",
name = "appName",
options ={'build_exe'{'excludes':excludes,'packages':packages,'include_files':includes}},
executables = [exe]
)
EDIT: The full error message traceback is:
File “C:\Users\slalo_000\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py”, line 14, in run module.run()
File “C:\Users\slalo_000\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py”, line 26, in run exec(code, m.__dict__
File “VSWv300.py”, line 20, in <module>
File “C:\Users\slalo_000\AppData\Local\Programs\Python\Python36\lib\site-packages\ffpyplayer\player\__init__.py”, line 10, in <module> from ffpyplayer.player.player import MediaPlayer
ImportError:DLL load failed: The specified module could not be found.
Any suggestions?

cx_Freeze not finding some TensorFlow imports

I recently wrote a library (in Python 3.6) and built a GUI for it using tkinter on Windows 10. The GUI is now finished, and I'm trying to freeze it using cx_Freeze.
The setup script runs perfectly fine (or at least I couldn't spot any error message or warning) and I can get my executable out of it. The problem is, when I run it, I get the following error message:
File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\profiler\profiler.py", line 22 in <module>
from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto
ModuleNotFoundError: No module named 'tensorflow.core.profiler.tfprof_log_pb2'
The reason why TensorFlow is mentioned here is that my library uses TensorFlow, and of course, so does my GUI. What the entire error message says is that when I'm importing tensorflow (import tensorflow as tf), the program tries to do from tensorflow.python import * and the profiler.py in tensorflow.python.profiler then tried to do the import that causes the error.
I found the file that causes the error, and when I do on IDLE from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto, it works perfectly fine.
Before reaching to that point, I encountered several similar problems (the cx_Freeze building without displaying any warning or error, but the .exe having some import errors), but I could so far fix them all by myself, mostly by adding them to the list of include_files in the setup script. I tried to do the same for this TensorFlow file, but it didn't work. I also tried including TensorFlow as a package in the setup script, or directly importing it all in my main.py, without success.
My setup.pyis the following (there might be some unnecessary includes with it, since I tried lots of things):
from cx_Freeze import setup, Executable
import os
import sys
os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tk8.6"
base = None
if sys.platform == "win32":
base = "Win32GUI"
includes = ["tkinter", "_tkinter", "numpy.core._methods", "numpy.lib.format", "tensorflow"]
include_files = ["C:\\Program Files\\Python36\\DLLs\\tcl86t.dll",
"C:\\Program Files\\Python36\\DLLs\\tk86t.dll",
"C:\\Program Files\\Python36\\DLLs\\_tkinter.pyd",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\core\\profiler\\tfprof_log_pb2.py",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\python\\profiler\\profiler.py",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\include\\tensorflow\\core\\profiler\\tfprof_log.pb.h"]
packages = []
setup(name = "Ap'Pear",
version = "0.1",
description = "Test executable",
options = {"build_exe": { "includes": includes, "include_files": include_files, "packages": packages}},
executables = [Executable(script = "main.py", targetName = "Ap'Pear.exe", base = base, icon = "images/icon.ico")],
)
I tried rebuilding TensorFlow and its dependencies from scratch, but it didn't solve anything either.
Thanks in advance!
I was able to resolve this problem by creating a blank __init__.py file in \path\to\python\Lib\site-packages\tensorflow\core\profiler. I am running python 3.5.2 and TensorFlow 1.5.0 so this solution may be specific to my installations.

import tkinter error

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?

Freezing exe with cx-freeze and tkinter with python 3.4

I am having trouble getting cx-freeze to make my executable, which makes heavy use of tkinter. My setup file code is as follows:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages":["tkinter"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "distthis",
version = "0.01",
description = "Report Generator",
options = {"build_exe": build_exe_options},
executables = [Executable("distthis.py", base=base)]
)
When I try to build this from the command line (in the same directory) I can open the program, but it won't open a filedialog. I think the problem may be with tkinter. Can anybody help?
Ok I found the answer here: Keep getting a 'filedialog' error after creating executable with cx_Freeze
Following the advice at the bottom of the page I changed the tkinter module imports to explicit ones and the problem was gone.
If anybody knows why this strange behaviour happens I would love to know!

using Cx_freeze with kivy in python 3.3 on windows error

I am using kivy 1.8.0 on Windows.
After finishing coding, I ran cx_freeze like this:
python setup.py build
This is setup.py:
import sys
from cx_Freeze import setup,Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name = 'KR Searcher',
version = '0.1',
description = 'aaaa',
executables = [Executable('kivyTest2.py',base=base)])
After freezing I ran kivyTest2.exe, then this error popped up:
Traceback(most recent call last):
File "C:\Python33\lib\logging\__init__.py", line 939, in emit
stream.write(msg)
AttributeError: 'NoneType' object has no attribute 'write'
and this repeats.
Before freezing kivyTest2.py runs well without any errors.
So how can I make .exe files with cx_freeze with Kivy without using Python 2.x?

Categories

Resources