带有Cx_freeze TCL_LIBRARY错误的Python pygame exe构建 [英] Python pygame exe build with cx_freeze TCL_LIBRARY error

查看:70
本文介绍了带有Cx_freeze TCL_LIBRARY错误的Python pygame exe构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在此处进行本教程,以在pygame中制作蛇游戏。这是我的setup.py代码:

I'm following this tutorial here to make a snakegame in pygame. Here is my setup.py code:

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
    )

当我尝试在命令提示符下进行构建时出现此错误

When I try to build that in the command prompt I get this error


C:\Users\Accounts\Documents\snake> C:/ Python3 5 / python setup.py构建正在运行,构建正在运行,运行build_exe文件 C:\Python35\lib\site-packages\cx_Freeze\hooks.py,第597行,位于load_tkinter tclSourceDir = os.environ [ TCL_LIBRARY]

C:\Users\Accounts\Documents\snake>C:/Python35/python setup.py build running build running build_exe File "C:\Python35\lib\site-packages\cx_Freeze\hooks.py", line 597, in load_tkinter tclSourceDir = os.environ["TCL_LIBRARY"]

文件 C:\Python35\lib\os.py,第681行,在getitem中将KeyError(key)从None调为KeyError:'TCL_LIBRARY'KeyError :'TCL_LIBRARY'

File "C:\Python35\lib\os.py", line 681, in getitem raise KeyError(key) from None KeyError: 'TCL_LIBRARY'KeyError: 'TCL_LIBRARY'

,它不会生成。有谁知道如何解决这一问题?谢谢

and it doesn't build. Does anyone know how to fix this? Thanks

推荐答案

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

I was getting a similar error and solved it successfully this morning! Add following lines to your setup.py code

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分别在您的系统上。

you may need to replace C:\Program Files\Python35\tcl\tcl8.6 and C:\Program Files\Python35\tcl\tk8.6 with the exact path of tcl8.6 and tk8.6 on your system respectively.

这篇关于带有Cx_freeze TCL_LIBRARY错误的Python pygame exe构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆