import _tkinter # If this fails your Python may not be configured for Tk

橙三吉。 提交于 2019-11-27 08:29:40

I had to scour pretty hard to figure this one out for myself. Not sure if this helps anyone but it worked for me. From what I understand these errors are generated when cx_freeze either cannot find all the dependencies or is grabbing incorrect ones.

First thing I did was to drill down into my python directory. Be VERY careful here and ensure you are looking where your python code is executing. Your IDE may give you this path if you do not know it. In cases of multiple installations or environments you may be off.

Once in there I identified which file was causing the error. For my situation it was a tkinter dependency. tcl86.dll and tk86.dll were the problem. You can see the lines I added. Then my logo actually started doing it so I had to add that. Now it works great. Here is a sample of my setup.py file (cx_freeze config).

from cx_Freeze import setup, Executable
import sys
import os

includes = []
include_files = [r"C:\Users\Ace\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll",
                 r"C:\Users\Ace\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll",
                 r"C:\Users\Ace\Desktop\IPNV\KP_App\FML\logo1.gif"]
os.environ['TCL_LIBRARY'] = r'C:\Users\Ace\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\Ace\AppData\Local\Programs\Python\Python36\tcl\tk8.6'
base = 'Win32GUI' if sys.platform == 'win32' else None


setup(name='KpApp', version='0.9', description='KP Report App',
      options={"build_exe": {"includes": includes, "include_files": include_files}},
      executables=[Executable(r'C:\Users\Ace\Desktop\IPNV\KP_App\FML\firstapp.py', base=base)])
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!