简体   繁体   English

当使用cx_Freeze和tkinter时,我得到:“DLL加载失败:找不到指定的模块。”(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)

When using cx_Freeze and Tkinter, I am given the message: 使用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.

Some things to note: 有些事情需要注意:

  • I want to use Python 3+ (Currently using 3.5.3, 32-bit). 我想使用Python 3+(目前使用3.5.3,32位)。 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. 据我所知,这给我留下了cx_Freeze或Nuitka。 Nuitka had problems of its own. Nuitka有自己的问题。
  • I am using Windows 10 Home Edition, 64-bit 我使用的是Windows 10 Home Edition,64位

Here is my current setup.py: 这是我目前的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) python的多个版本(以及相应的cx_Freeze / Tkinter版本)
  • Both 32-bit and 64-bit versions 32位和64位版本
  • Replacing Tkinter with easygui (apparently easygui needs Tkinter to work) 用easygui取代Tkinter(显然easygui需要Tkinter才能工作)
  • Checking the PATH variables 检查PATH变量
  • Restarting my computer (Don't know what I expected) 重新启动我的电脑(不知道我的预期)
  • Uninstalling other versions of python and repairing the correct version 卸载其他版本的python并修复正确的版本
  • Placing the following in my compile bat file (Definetly the correct paths): 将以下内容放在我的编译bat文件中(绝对是正确的路径):

     set TCL_LIBRARY=C:\\Users\\VergilTheHuragok\\AppData\\Local\\Programs\\Python\\Python35-32\\tcl\\tcl8.6 set TK_LIBRARY=C:\\Users\\VergilTheHuragok\\AppData\\Local\\Programs\\Python\\Python35-32\\tcl\\tk8.6 
  • Placing the following in my setup.py: 将以下内容放在我的setup.py中:

    options={"build_exe": {"includes": ["tkinter"]}}
  • Along with: 随着:
    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"]

(And yes, those were included in setup() in one way or another) (是的,那些以某种方式包含在setup()中)


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. 希望有人可以帮助我找到另一个解决方案,因为我的问题似乎是持久的。

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. 我不得不将我的python目录的DLLs文件夹中的tk86t.dll和tcl86t.dll文件复制到我正在尝试编译的main.py的build文件夹中。

This, in conjunction with having 这与,有

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

at the top of my compile.bat, and including 在我的compile.bat的顶部,包括
"include_files": ["tcl86t.dll", "tk86t.dll"]
in my build_exe_options in setup.py, seems to have done the trick. 在我的setup.py中的build_exe_options中,似乎已经完成了这个伎俩。

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

And here is my compile.bat (updated to show all steps): 这是我的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  

I found this solution here . 我在这里找到了解决方案。

图片

to solve this problem just copy the files 1.tcl86t.dll 2.tk86t.dll from this path C:\\Users\\h280126\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs and placed in our .exe path C:\\Users\\h280126\\PycharmProjects\\my_tool\\build\\exe.win32-3.6 it is working fine :) 解决这个问题只需从这个路径C:\\ Users \\ h280126 \\ AppData \\ Local \\ Programs \\ Python \\ Python36-32 \\ DLLs复制文件1.tcl86t.dll 2.tk86t.dll并放在我们的.exe路径C: \\ Users \\ h280126 \\ PycharmProjects \\ my_tool \\ build \\ exe.win32-3.6它运行正常:)

After fixing these issues cx_freeze was still unable to import the dependencies of pandas (namely numpy ). 修复这些问题后, cx_freeze仍然无法导入pandas的依赖关系(即numpy )。 To fix this I literally copied and pasted the entire folders into the directory of the .py file I was trying to compile. 为了解决这个问题,我将整个文件夹复制并粘贴到我试图编译的.py文件的目录中。 The executable needs to be in the same directory (so it isn't necessarily stand-alone) but it runs with pandas and numpy . 可执行文件需要位于同一目录中(因此它不一定是独立的),但它与pandasnumpy一起运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cx_Freeze ImportError: DLL load failed while importing _ctypes: 找不到指定的模块 - cx_Freeze ImportError: DLL load failed failed while importing _ctypes: The specified module could not be found cx_Freeze导入错误:DLL加载失败:找不到指定的模块 - cx_Freeze Import Error: DLL load failed: The specified module could not be found Python 3.3.4 Cx_Freeze ImportError:DDL加载失败:找不到指定的模块 - Python 3.3.4 Cx_Freeze ImportError: DDL load failed: The specified module could not be found 我收到“DLL 加载失败:找不到指定的模块。” 将 Cython 与 Numpy 程序一起使用时 - I am getting a "DLL load failed: The specified module could not be found." when using Cython with a Numpy program python Windows“ ImportError:DLL加载失败:找不到指定的模块。”加载编译的扩展名时 - python Windows “ImportError: DLL load failed: The specified module could not be found.” When loading compiled extension 运行python manage.py shell我得到错误:DLL加载失败:找不到指定的模块。 - Running python manage.py shell i get Error: DLL load failed: The specified module could not be found. cx_freeze,导入错误:DLL加载失败(tkinter) - cx_freeze, import error: DLL load failed (tkinter) CX_freeze 可执行文件将不起作用。 _tkinter DLL 加载失败 - CX_freeze executable will not work. _tkinter DLL load failed 使用cx_Freeze创建可执行文件(无法导入_tkinter,DLL加载失败) - Using cx_Freeze to create executable (cannot import _tkinter, DLL load failed) 导入错误:DLL 加载失败:找不到指定的模块。(Keras) - ImportError: DLL load failed: The specified module could not be found.(Keras)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM