Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

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

When using cx_Freeze and Tkinter, I am given the message:

File "C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32libkinter\__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.

Some things to note:

  • I want to use Python 3+ (Currently using 3.5.3, 32-bit). Don't really care about a specific version, whatever works.
  • My project has multiple files I need to compile. As far as I can tell, that leaves me with cx_Freeze or Nuitka. Nuitka had problems of its own.
  • I am using Windows 10 Home Edition, 64-bit

Here is my current 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={'': ''},  
      )

I have tried many solutions from all corners of the internet. Including but not limited to:

  • Multiple versions of python (and the corresponding cx_Freeze/Tkinter versions)
  • Both 32-bit and 64-bit versions
  • Replacing Tkinter with easygui (apparently easygui needs Tkinter to work)
  • Checking the PATH variables
  • Restarting my computer (Don't know what I expected)
  • Uninstalling other versions of python and repairing the correct version
  • Placing the following in my compile bat file (Definetly the correct paths):

    set TCL_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32clcl8.6
    set TK_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32clk8.6
    
  • Placing the following in my setup.py:

    options={"build_exe": {"includes": ["tkinter"]}}
  • Along with:
    include_files = [r"C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32DLLscl86t.dll",
                     r"C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32DLLsk86t.dll"]

(And yes, those were included in setup() in one way or another)


Thanks for any help, it's greatly appreciated. And yes, I have looked at just about every solution to this problem on this site. Hoping someone could help me find yet another solution since my problem seems to be persistent.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found a solution!

I had to copy the tk86t.dll and tcl86t.dll files from my python directory's DLLs folder into the build folder with the main.py I was trying to compile.

This, in conjunction with having

set TCL_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35clcl8.6  
set TK_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35clk8.6

at the top of my compile.bat, and including
"include_files": ["tcl86t.dll", "tk86t.dll"]
in my build_exe_options in setup.py, seems to have done the trick.

Here is my current 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={'': ''},  
    )  

And here is my compile.bat (updated to show all steps):

@echo off
set TCL_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32clcl8.6
set TK_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32clk8.6
RD /S /Q "C:UsersVergilTheHuragokDesktopPythonProjectCompiledin"
mkdir "C:UsersVergilTheHuragokDesktopPythonProjectCompiledin"
xcopy /s "C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32DLLscl86t.dll" "C:UsersVergilTheHuragokDesktopPythonProjectCompiledincl86t.dll"
xcopy /s "C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32DLLsk86t.dll" "C:UsersVergilTheHuragokDesktopPythonProjectCompiledink86t.dll"
cd "C:UsersVergilTheHuragokDesktopPythonProject"
cxfreeze main.py --target-dir "C:UsersVergilTheHuragokDesktopPythonProjectCompiledin" --target-name "launch.exe"
pause  

I found this solution here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...