KeyError: 'TCL_LIBRARY' when building using cx_freeze

KeyError: 'TCL_LIBRARY' when building using cx_freeze

尝试使用 cx_freeze 构建我的文件时出现错误

    raise KeyError(key) from None
     KeyError: 'TCL_LIBRARY'

我知道还有其他帖子对此进行了描述,但我已经尝试添加

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll')
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')

这是其他帖子推荐的,但我仍然得到同样的错误

到目前为止,这是我的代码

from cx_Freeze import setup, Executable
import sys, os


shortcut_table = [
    ("DesktopShortcut",        # Shortcut
     "DesktopFolder",          # Directory_
     "program",           # Name
     "TARGETDIR",              # Component_
     "[TARGETDIR]main.exe",# Target
     None,                     # Arguments
     None,                     # Description
     None,                     # Hotkey
     "icon.ico",                     # Icon
     None,                     # IconIndex
     None,                     # ShowCmd
     'TARGETDIR'               # WkDir
     )
    ]

base = None
if sys.platform == "win32": base = "Win32GUI"

os.environ['TCL_LIBRARY'] = "C:\Program Files\Python35-32\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\Program Files\Python35-32\tcl\tk8.6"


msi_data = {"Shortcut": shortcut_table}
bdist_msi_options = {'data': msi_data}

executables = [Executable("main.py", shortcutName='2048', shortcutDir='DesktopFolder', icon='icon.ico', base=base), Executable("extras.pyw"),]


setup(
    name = '2048',
    author = 'Ethan',
    options={
        "build_exe": {
            "packages":["pygame", "sys", "random", "os", "ctypes"],
            "include_files":["scores.txt",
            "icon.ico",
            ]
            }},
    executables = executables,
    version = "1.0"
)

编辑:代码更改

更改代码后,它目前运行没有错误,但只创建了一个包含 ul-launchable exe 的文件夹

build
   exe.win-amd64-3.6
      api-ms-win-crt-conio-l1-1-0.dll
      api-ms-win-crt-convert-l1-1-0.dll
      api-ms-win-crt-environment-l1-1-0.dll
      api-ms-win-crt-filesystem-l1-1-0.dll
      api-ms-win-crt-heap-l1-1-0.dll
      api-ms-win-crt-locale-l1-1-0.dll
      api-ms-win-crt-math-l1-1-0.dll
      api-ms-win-crt-process-l1-1-0.dll
      api-ms-win-crt-runtime-l1-1-0.dll
      api-ms-win-crt-stdio-l1-1-0.dll
      api-ms-win-crt-string-l1-1-0.dll
      api-ms-win-crt-time-l1-1-0.dll
      main.exe
      python36.dll
      VCRUNTIME140.dll

编辑 2: 所以我做了一些修改,发现 TCL 错误来自于包含 ctypes(不知道为什么)。所以我删除了它并将我的 python 版本更改为 3.6 并且它构建完美。但我更愿意包含 ctypes,因为我用它来禁用应用程序缩放。

是否有其他方法来处理屏幕缩放或修复 TCL 错误?

cx_freeze 不适用于 python 3.7 所以切换到 3.6 允许它工作,然后添加

import os.path

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

设置目录以便使用 ctypes