猿问

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

当我使用pygame程序时,cx_Freeze遇到键盘错误KeyError: 'TCL_Library'。为什么会得到这个,如何解决?


我的setup.py如下:


from cx_Freeze import setup, Executable


setup(

    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")],

    )


胡说叔叔
浏览 625回答 3
3回答

叮当猫咪

除了使用特定于安装的绝对路径来设置环境变量外,C:\\LOCAL_TO_PYTHON\\...您还可以使用__file__Python标准软件包的属性来动态派生必要的路径,例如os:import os.pathPYTHON_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,      # ...)
随时随地看视频慕课网APP

相关分类

Python
我要回答