Search code examples
pythonuser-interfaceexecx-freeze

create python script to exe


I am trying to use in cv_freeze library for create my python script to exe GUI application. my application using tkinter only, but when I try to build the exe file: I get an TCL_LIBRARY error. why is that? this is my setup code:

import cx_Freeze
import sys
import matplotlib

base = None

if sys.platform == 'win32':
    base = "Win32GUI"

executables = [cx_Freeze.Executable("tkinterVid28.py", base=base, icon="clienticon.ico")]

cx_Freeze.setup(
    name = "SeaofBTC-Client",
    options = {"build_exe": {"packages":["easygui","matplotlib"]}},
    version = "0.01",
    description = "Sea of BTC trading application",
    executables = executables
    )

and this is myGUI python code:

import tkinter
top = tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()

I am using in python 3.6, thanks for helping or not helping.


Solution

  • Put this before in the first 2 lines of your cx_Freeze setup.py code.

    os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tcl8.6'
    os.environ['TK_LIBRARY'] = r'C:\Program Files\Python35-32\tcl\tk8.6'
    

    Replace the paths to your correct python paths. If your python path is C:\Python36-19 then you would want to do

    os.environ['TCL_LIBRARY'] = r'C:\Python36-19\tcl\tcl8.6'
    os.environ['TK_LIBRARY'] = r'C:\Python36-19\tcl\tk8.6'
    

    If you need help finding your Python path let me know. In windows (and I think linux), you can run where python and you want to use the path you get up to the PythonXX-XX folder then do \tcl\tcl8.6 and \tcl\tk8.6