import tkinter error - python

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?

Related

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.

Python: cx_Freeze: Noting happend if I click the .exe

nothing happend when I double click the test.exe.....
But to start from the beginning, I create a Little python Programm which is in test.py:
test.py:
import tkinter
top = tkinter.Tk()
top.mainloop()`
Then I use cx_Freeze to convert test.py to an exe:
The following lines are in my Setup.py:
import sys
from cx_Freeze import setup, Executable
import os
build_exe_options = {"packages": ["tkinter"], "include_files":[r"C:\\Program
Files\\Python36\\tcl\\tcl8.6",
r"C:\\Program Files\\Python36\\tcl\\tk8.6"]}
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" `
setup( name = "stest",
version = "1.0",description = "hello",
options = {"build_exe": build_exe_options},
executables = [Executable("test.py", base='Win32GUI')])`
Then I open a cmd and type in the following " python setup.py build". No erros appears while Building.
But if I click the test.exe nothing happend.
Where is my mistake?
Do NOT install cx_freeze by "pip install cx_freeze", because an old Version will be installed,
instead go to https://pypi.python.org/pypi/cx_Freeze and then download the right version.
Use for example pip install cx_Freeze-6.0b1-cp36-cp36m-win_amd64.whl.
Finally copy the file "tcl86t.dll" and "tk86t.dll" into the build folder

creating a exe file using python 3.6 and cx_freeze5.0.1

I'm having an issue opening the .exe file that I created using cx_freeze 5.0.1 and python 3.6. (Windows 10 64 bit)
I'm attaching the error I received and setup.py which I used to create the file.
The issue is coming from tkinter not being recognized
I've been looking for hours for a solution online but I'm pretty clueless
import sys,os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r'C:\Users\user\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\user\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(
name = "Name of app",
version = "0.1",
description = "Any Description you like",
executables = [Executable("App.py", base = "Win32GUI")])

Using cx_Freeze to create executable (cannot import _tkinter, DLL load failed)

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.

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!

Categories

Resources