Reputation: 35
I have a python script, which I am trying to make it executable using cx-freeze. This is my script.py file
from cx_Freeze import setup,Executable
import tkinter
import sys
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Admin\\Anaconda3\\tcl\\tcl8.6"
os.environ['TCL_LIBRARY'] = "C:\\Users\\Admin\\Anaconda3\\tcl\\tk8.6"
includes = []
excludes = ['tkinter']
packages = []
base = "Win32GUI"
setup(
name = 'myapp',version = '0.1',description = 'app',author = 'user',
options = {'build_exe': {'excludes':excludes,'packages':packages}},
executables = [Executable('emetor1.py')]
)
When executed with "python script.py build", the build folder is created with the .exe file. But when I execute the .exe file it gives me "ModuleNotFoundError: No module named tkinter". I put on the os.environ the path of the package, but I still dont understand why it does not recognize it. Please if someone know how to fix this, I would be very thankful.
I am using Windows, and I used "import tkinter" in my main python script. The main python fyle executes normally with the comand python mainprog.py, but the problem is in the .exe file when created by build command.
Upvotes: 2
Views: 3000
Reputation: 1
After a lot of research, and following the instructions, nothing worked. I checked that I already had the tcl8.6 and tk8.6 files inside lib, but I noticed that the Tkinter folder started with a capital letter and it looked for "tkinter", so I changed the "T" to "t", and amazingly that seems functional.
Upvotes: 0
Reputation: 1
from cx_Freeze import setup, Executable
import tkinter
import sys
import os
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "includes": ["tkinter"],"include_files": ["ico.png"]}
# 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="merge",
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("merge.py", base=base)])
Had similar issue. This format for setup.py solved it for me.
Upvotes: -1
Reputation: 192
Excludes means that the package will not be included. I suggest you remove the 'tkinter' from excludes = ['tkinter'] in your setup script.
Edit: Try this setup script:
from cx_Freeze import setup,Executable
import sys
import os
os.environ['TCL_LIBRARY'] = r'C:\Users\Admin\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Admin\Anaconda3\tcl\tk8.6'
includes = []
include_files = [r"C:\Users\Admin\Anaconda3\DLLs\tcl86t.dll",
r"C:\Users\Admin\Anaconda3\DLLs\tk86t.dll"]
packages = []
base = "Win32GUI"
setup(
name = 'myapp',version = '0.1',description = 'app',author = 'user',
options = {'build_exe': {'includes':includes, 'include-files':include_files,'packages':packages}},
executables = [Executable('emetor1.py', base=base)]
)
Upvotes: 3