When I use cx_Freeze
I get a keyerror KeyError: 'TCL_Library'
while building my pygame program. Why do I get this and how do I fix it?
My setup.py is below:
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")],
)
Just put this before the setup at setup.py
And run it:
This worked fine for me.
If you get following error with python 3.6:
copying
C:\LOCAL_TO_PYTHON\Python35-32\tcl\tcl8.6
->build\exe.win-amd64-3.6\tcl
error:[Errno 2] No such file or directory: 'C:\\LOCAL_TO_PYTHON\\Python35-32\\tcl\\tcl8.6'
Simply create LOCAL_TO_PYTHON dir in C:\ then create Python35-32 dir inside it. Now copy tcl dir from existing Python36 dir (in C:) into Python35-32.
Then it works fine.
**I did this steps and created a .exe file into the build dir but if ı try to click app dont wait on the screen instantly quick, my codes here **
You can work around this error by setting the environment variables manually:
You can also do that in the
setup.py
script:But I found that actually running the program doesn't work. On the cx_freeze mailinglist it was mentioned:
But perhaps you have more luck ... Here's the bug report.
Instead of setting the environment variables using installation specific absolute paths like
C:\\LOCAL_TO_PYTHON\\...
you may also derive the necessary paths dynamically using the__file__
attribute of Python standard package likeos
:After this fix the executable file will be created, but you will probably get a "DLL not found error" when you try to execute it - at least with Python 3.5.3 and cx_Freeze 5.0.1 on Windows 10.
When you add the following options, the necessary DLL-files will be copied automatically from the Python-Installation directory to the build-output of cx-Freeze and you should be able to run your Tcl/Tk application:
If you get following error with python 3.6:
Simply create
LOCAL_TO_PYTHON
dir inC:\
then createPython35-32
dir inside it. Now copytcl
dir from existingPython36
dir (inC:\
) intoPython35-32
.Then it works fine.