Python pygame exe build with cx_freeze TCL_LIBRARY

2019-03-29 09:26发布

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

2条回答
我只想做你的唯一
2楼-- · 2019-03-29 09:53

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-03-29 09:53

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

查看更多
登录 后发表回答