cx_freeze Tkinter 'Module not Found'

て烟熏妆下的殇ゞ 提交于 2021-02-10 14:21:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!