Python pygame exe使用cx_freeze TCL_LIBRARY错误构建

时间:2016-01-22 05:04:23

标签: python build pygame command-prompt cx-freeze

我按照本教程here在pygame中制作蛇游戏。这是我的setup.py代码:

import cx_Freeze

executables = [cx_Freeze.Executable("snake.py")]

cx_Freeze.setup(
    name="Snake",
    options={"build_exe":{"packages":["pygame"], "include_files":["apple.png","Aenemy.png","bomb.png","cherry.png","enemy.png","fire.png","iceimg.png","snakebod(2).png","snakebod.png","Explosion.wav","Explosion2.wav","jump.wav","Pickup_Coin.wav","Powerup.wav","openingsong.mp3","highscores.txt",]}},

    description = "Snake Game made in python with pygame.",
    executables = executables
    )

当我尝试在命令提示符中构建它时,我收到此错误

  

C:\ Users \ Accounts \ Documents \ snake> C:/ Python35 / python setup.py构建运行构建运行build_exe文件" C:\ Python35 \ lib \ site-packages \ cx_Freeze \ hooks.py&# 34;,第597行,在load_tkinter中tclSourceDir = os.environ [" TCL_LIBRARY"]

     

文件" C:\ Python35 \ lib \ os.py",第681行,在getitem中从无KeyError引发KeyError(key):' TCL_LIBRARY' KeyError:' TCL_LIBRARY'

并且它没有构建。有谁知道如何解决这一问题?感谢

2 个答案:

答案 0 :(得分:9)

我收到了类似的错误,今天早上成功解决了! 将以下行添加到setup.py代码

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

您可能需要在系统中使用tcl8.6和tk8.6的确切路径替换C:\ Program Files \ Python35 \ tcl \ tcl8.6和C:\ Program Files \ Python35 \ tcl \ tk8.6分别

答案 1 :(得分:0)

假设您使用的是Windows操作系统:

在您的机器用户和系统变量

中添加名为TCL_Library和TK_Library的2个环境变量

TK_Library

TCL_Library

Env variable