问题
I am trying to create an executable from my python scripts. I am using Windows 7, cx_freeze 5.0.2 and Python 3.6.
I know Tkinter isn't included in the normal libraries and that you need to add something similar to the following 2 lines:
os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python35\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python35\\tcl\\tk8.6"
Except of course for 3.6 and in my location, however I can't find their directory in Anaconda 3.6
I create the following file called setup.py
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"]}
# 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 = "McCabe-Thiele",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("GUI.py", base=base)])
and run it from the cmd line with python setup.py bdist_msi
.
It successfully creates the dist which then successfully installs.
However when I then run the .exe the following error occurs:
ModuleNotFoundError: no module named 'tkinter'
Thank you in advance for any help with this
回答1:
On the third line add ,"includes":["tkinter"]
Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"],"includes":["tkinter"]}
It worked for me when I run it with python setup.py build
Updated Code from Question:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"],"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 = "McCabe-Thiele",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("GUI.py", base=base)])
来源:https://stackoverflow.com/questions/44508303/cx-freeze-tkinter-module-not-found