使用 cx_Freeze 和 tkinter 时,我得到:"DLL load failed: The specified module could not be found." (Python 3.5.3)

When using cx_Freeze and tkinter I get: "DLL load failed: The specified module could not be found." (Python 3.5.3)

当使用 cx_Freeze 和 Tkinter 时,我收到消息:

File "C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 35, 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.

一些注意事项:

这是我现在的 setup.py:

from cx_Freeze import setup, Executable    
import sys  

build_exe_options = {"packages": ["files", "tools"]}  

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

setup(name="Name",  
      version="1.0",  
      description="Description",  
      options={"build_exe": build_exe_options},  
      executables=[Executable("main.py", base=base)],  
      package_dir={'': ''},  
      )

我尝试了来自互联网各个角落的许多解决方案。包括但不限于:

    options={"build_exe": {"includes": ["tkinter"]}}
    include_files = [r"C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\DLLs\tcl86t.dll",\
                     r"C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35-32\DLLs\tk86t.dll"]

(是的,这些以某种方式包含在 setup() 中)


感谢您的帮助,非常感谢。是的,我已经查看了该站点上几乎所有解决此问题的方法。希望有人能帮我找到另一个解决方案,因为我的问题似乎一直存在。

找到解决办法了!

我不得不将 tk86t.dll 和 tcl86t.dll 文件从我的 python 目录的 DLLs 文件夹复制到我试图编译的 main.py 的构建文件夹中。

这个,连同

set TCL_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35\tcl\tcl8.6  
set TK_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python35\tcl\tk8.6

在我的 compile.bat 的顶部,包括
"include_files": ["tcl86t.dll", "tk86t.dll"]
在我的 build_exe_options 在 setup.py 中,似乎已经成功了。

这是我目前的setup.py:

from cx_Freeze import setup, Executable  
import sys  

build_exe_options = {"packages": ["files", "tools"], "include_files": ["tcl86t.dll", "tk86t.dll"]}  

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

setup(name="Name",  
    version="1.0",  
    description="Description",  
    options={"build_exe": build_exe_options},  
    executables=[Executable("main.py", base=base)],  
    package_dir={'': ''},  
    )  

这是我的 compile.bat(已更新以显示所有步骤):

@echo off
set TCL_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6
set TK_LIBRARY=C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6
RD /S /Q "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin"
mkdir "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin"
xcopy /s "C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll" "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin\tcl86t.dll"
xcopy /s "C:\Users\VergilTheHuragok\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll" "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin\tk86t.dll"
cd "C:\Users\VergilTheHuragok\Desktop\PythonProject\"
cxfreeze main.py --target-dir "C:\Users\VergilTheHuragok\Desktop\PythonProjectCompiled\bin" --target-name "launch.exe"
pause  

我找到了这个解决方案 here

要解决这个问题只需复制文件 1.tcl86t.dll 2.tk86t.dll 从这个路径 C:\Users\h280126\AppData\Local\Programs\Python\Python36-32\DLLs 并放在我们的 .exe 路径中 C:\Users\h280126\PycharmProjects\my_tool\build\exe.win32-3.6 它工作正常:)

修复这些问题后,cx_freeze 仍然无法导入 pandas(即 numpy)的依赖项。为了解决这个问题,我将整个文件夹复制并粘贴到我试图编译的 .py 文件的目录中。可执行文件需要在同一个目录中(因此它不一定是独立的)但它与 pandasnumpy.

一起运行