Required environment variables TCL_LIBRARY and TK_LIBRARY not set by Python 3.5

Issue #155 new
Aivar Annamaa
created an issue

When freezing Tkinter programs in Windows 7 with Python 3.5 32bit, cx_freeze fails, because it expects environment variables TCL_LIBRARY and TK_LIBRARY to be set.

A workarond of setting these manually seems to work

Comments (15)

  1. David Pratt

    Could you specify exactly how to manually set the TCL_LIBRARY and TK_LIBRARY variables? I'm getting an error when trying to freeze a python file that uses pygame which says: "File "C:\Program Files (x86)\Python 3.5\lib\os.py", line 681, in getitem KeyError: 'TCL_LIBRARY'"

    I've tried editing the os.py file but it doesn't change my error message at all. Any suggestions?

  2. David Pratt

    Sorry, the error says: ... "File "C:\Program Files (x86)\Python 3.5\lib\os.py", line 681, in getitem raises KeyError(key) from None KeyError: 'TCL_LIBRARY'"

  3. David Pratt

    So does that go inside the "setup.py" file that is used to freeze my other .py file?


    from cx_Freeze import setup, Executable

    set TCL_LIBRARY = C:\Program Files (x86)\Python 3.5\tcl\tcl8.6 set TK_LIBRARY = C:\Program Files (x86)\Python 3.5\tcl\tcl8.6

    build_exe_options = {'excludes': ['Tkinter']} script = [Executable('knit2.py')]

    setup( name = '', version = '', description = '', options = {'build_exe': build_exe_options}, executables = script )


  4. David Pratt

    from cx_Freeze import setup, Executable

    set TCL_LIBRARY = C:\Program Files (x86)\Python 3.5\tcl\tcl8.6 set TK_LIBRARY = C:\Program Files (x86)\Python 3.5\tcl\tcl8.6

    build_exe_options = {'excludes': ['Tkinter']} script = [Executable('knit2.py')]

    setup( name = '', version = '', description = '', options = {'build_exe': build_exe_options}, executables = script )

  5. Turson

    Hi! Tried cx_Freeze yesterday and got the same error. Solved it with adding to my setup.py these lines:

    import os
    
    os.environ['TCL_LIBRARY'] = "C:\\Program Files (x86)\\Python35-32\\tcl\\tcl8.6"
    os.environ['TK_LIBRARY'] = "C:\\Program Files (x86)\\Python35-32\\tcl\\tk8.6"
    

    Also, for correct work of tkinter GUI, I've imported tk86.dll and tcl86t.dll to exe.win* folder.

  6. sidthekid97

    Hi! I had the same problem with LIBRARY but fixed it with Turson's solution. So now I am able to build executable program but when I run it I get "DLL load failed: The specified module could not be found". I used tkinter GUI so that is probably the problem but I don't know how to import tk86.dll and tcl86t.dll to exe.win* folder. Could someone please explain in details since I'm new to programming. Thank you

  7. Anon

    Hi, I have done as above also.. could sidthekid97 explain how he imported into setup.py? tried "import tk86.dll" and throws an error

    File "setup.py", line 4, in <module> import tk86.dll ImportError: No module named 'tk86'

    Thanks in advance, been working on this for some time!

  8. Anon

    Ok this has been solved now as follows:

    copy tk86.dll and tcl86t.dll (and any other .dll your program needs) from the 'DLL's' folder and paste into the 'exe.win' folder that has been created in the 'build' folder.

    Now run and it works perfect...

    Thanks!

  9. sidthekid97

    I solved like this:

    opts={'include_files':['myfile.gif','tk86t.dll','tcl86t.dll'],'includes':['re']}

    import os

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

  10. David Lukas Müller

    Trying to python setup.py build the included samples/Tkinter example with Python 3.5.3 on Windows 10 this weekend, I ran into the same problem. I'm new to cx_Freeze and it took me a while to fill in the missing gaps in the solution provieded by @sidthekid97 .

    Finally I generalized this workaround to be more agnostic to the actual location of the Python 3.5 installation and extended the included samples/Tkinter example to copy the required Tcl/Tk DLLs automatically:

    import sys
    from cx_Freeze import setup, Executable
    
    # <added>
    import os.path
    PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
    os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
    os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
    # </added>
    
    base = None
    if sys.platform == 'win32':
        base = 'Win32GUI'
    
    executables = [
        Executable('SimpleTkApp.py', base=base)
    ]
    
    # <added>
    options = {
        'build_exe': {
            'include_files':[
                os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
                os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
             ],
        },
    }
    # </added>
    
    setup(name = 'simple_Tkinter',
          version = '0.1',
          description = 'Sample cx_Freeze Tkinter script',
          # <added>
          options = options,
          # </added>
          executables = executables
          )
    

    I hope that I'll find some time within the next few days, to create the according pull request.

  11. David Howland

    I ran into this same issue on Python 3.6 and had to take the same actions. It was missing the .dll files and I had to define the TCL_LIBRARY variables. tkinter support seems to be really broken on Windows.

    In addition to those issues, the code that locates .dll files really seems to be broken. It included TortoiseSVN dlls for no reason, and it selected the wrong MSVCRT files.

  12. fireundubh

    I have the same issue with api-ms-win*.dll files being included from TortoiseSVN for no reason. I removed TortoiseSVN from my system PATH, and cx_freeze decided to copy the same DLLs from LLVM, which is also in my user PATH. It seems to be copying those DLLs from the first path it finds.

  13. Log in to comment