为了账号安全,请及时绑定邮箱和手机立即绑定

我使用cx_Freeze时出现KeyError:“ TCL_Library”

我使用cx_Freeze时出现KeyError:“ TCL_Library”

胡说叔叔 2019-09-24 15:16:36
当我使用pygame程序时,cx_Freeze遇到键盘错误KeyError: 'TCL_Library'。为什么会得到这个,如何解决?我的setup.py如下:from cx_Freeze import setup, Executablesetup(    name = "Snakes and Ladders",    version = "0.9",    author = "Adam",    author_email = "Omitted",    options = {"build_exe": {"packages":["pygame"],                         "include_files": ["main.py", "squares.py",                         "pictures/Base Dice.png", "pictures/Dice 1.png",                         "pictures/Dice 2.png", "pictures/Dice 3.png",                         "pictures/Dice 4.png", "pictures/Dice 5.png",                         "pictures/Dice 6.png"]}},    executables = [Executable("run.py")],    )
查看完整描述

3 回答

?
叮当猫咪

TA贡献1776条经验 获得超12个赞

除了使用特定于安装的绝对路径来设置环境变量外,C:\\LOCAL_TO_PYTHON\\...您还可以使用__file__Python标准软件包的属性来动态派生必要的路径,例如os:


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')

修复此问题后,将创建可执行文件,但尝试执行该文件时可能会出现“找不到DLL错误”-至少在Windows 10上使用Python 3.5.3和cx_Freeze 5.0.1。


添加以下选项时,必要的DLL文件将自动从Python安装目录复制到cx-Freeze的build-output中,并且您应该能够运行Tcl / Tk应用程序:


options = {

    'build_exe': {

        'include_files':[

            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),

            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),

         ],

    },

}


# ...


setup(options = options,

      # ...

)


查看完整回答
反对 回复 2019-09-24
  • 3 回答
  • 0 关注
  • 624 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信