Search code examples
pythonpython-3.xcx-freeze

cx_freeze, import error: DLL load failed (tkinter)


click to see the error

click to see the error

that error apprerd after I builded with cx_freeze. and my setup.py code is

import sys
from cx_Freeze import setup, Executable
import numpy.core._methods
import numpy.lib.format
import os


build_exe_options = dict(
    compressed = True,
    includes = ["os","operator", "requests", "konlpy", "bs4", "copy", "jpype","numpy","idna","lxml","datetime","pygame","os","PIL","wordcloud","matplotlib","tkinter"],
    include_files = []
)





os.environ['TCL_LIBRARY'] = r'C:\Users\airne\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\airne\Anaconda3\tcl\tk8.6'

setup(
    name = "Search Key Word",
    version = "2.0",
    author = "airnew",
    description = "검색엔진 키워드 분석",
    options = {"build_exe": {"packages":["os","operator","requests","konlpy","bs4","copy","jpype","numpy","idna","lxml","datetime","pygame","os","PIL","wordcloud","matplotlib","tkinter"]}},
    executables = [Executable("SearchKeyWord.py",base = "Win32GUI")],
)

Solution

  • I've had similar problem some time ago. That worked for me:

    import sys
    from cx_Freeze import setup, Executable
    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')
    
    options = {
        'build_exe': {
            'include_files':[
                os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
                os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
             ],
        },
    }