Python pygame exe build with cx_freeze TCL_LIBRARY error

强颜欢笑 提交于 2019-12-05 00:48:07

问题


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:/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"]

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


回答1:


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"

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.




回答2:


Assuming you are using windows operating system:

Add 2 environment variable named TCL_Library and TK_Library in your machines user and system variable

TK_Library

TCL_Library

Env variable



来源:https://stackoverflow.com/questions/34939356/python-pygame-exe-build-with-cx-freeze-tcl-library-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!