CX_freeze可执行文件无效。 _tkinter DLL加载失败

时间:2017-10-23 01:08:07

标签: python tkinter cx-freeze

我遇到与许多其他问题相同的问题,但发现还没有解决方案。这是在Windows 10 64位,Python 3.6 32位。

我尝试在安装文件中多次卸载,64位Python,各种路径和变量组合。

我觉得令人困惑的是,exe文件中的回溯是指我的Python文件夹中的文件路径,而不是可执行文件所在的构建文件夹。我原本以为这个exe应该是“无辜”的python文件夹的存在吗?

从exe文件输出

    Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "main3.py", line 2, in <module>
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\appJar\__init__.py", line 2, in <module>
    from appJar.appjar import gui
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\appJar\appjar.py", line 23, in <module>
    from tkinter import *
  File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: DLL load failed: The specified module could not be found.

我的cx_freeze安装文件 -

from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'C:\Program Files (x86)\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files (x86)\Python36-32\tcl\tk8.6'

build_exe_options={
"includes": [],
"packages": ["os","tkinter"],
"include_files" : [r'C:\Program Files (x86)\Python36-32\DLLs\tcl86t.dll',
r'C:\Program Files (x86)\Python36-32\DLLs\tk86t.dll']
}

setup(name = "main" ,
      version = "0.1" ,
      description = "" ,
      options={"build.exe":build_exe_options},
      executables = [Executable("main3.py", base=None, targetName="hexml.exe")])

1 个答案:

答案 0 :(得分:2)

我终于找到了答案。设置文件中包含文件tcl86t.dlltk86t.dll的行由于某种原因未能完成工作。必须在路径格式化中出现一些错误。

有效的方法是从Python\Dlls文件夹手动复制它们并将它们粘贴到新可执行文件所在的exe.win文件夹中。

我随后发现了here一个获取正确路径的setup.py脚本。 V现在开心。

from cx_Freeze import setup, Executable
import os
import sys

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'),
         ],
    },
}

setup(name = "main" ,
      version = "0.1" ,
      description = "" ,
      options=options,
      executables = [Executable("main3.py", base=None, targetName="hexml.exe")])