加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

当使用cx_Freeze和tkinter时,我得到:“DLL加载失败:找不到指定

发布时间:2020-12-14 04:20:17 所属栏目:Windows 来源:网络整理
导读:使用cx_Freeze和Tkinter时,我收到消息: File "C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32libtkinter__init__.py",line 35,in moduleimport _tkinter # If this fails your Python may not be configured for TkImportError:
使用cx_Freeze和Tkinter时,我收到消息:
File "C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32libtkinter__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.

有些事情需要注意:

>我想使用Python 3(目前使用3.5.3,32位).无论如何都不关心特定版本.
>我的项目有多个我需要编译的文件.据我所知,这给我留下了cx_Freeze或Nuitka. Nuitka有自己的问题.
>我使用的是Windows 10 Home Edition,64位

这是我目前的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={'': ''},)

我从互联网的各个角落尝试了很多解决方案.包括但不仅限于:

> python的多个版本(以及相应的cx_Freeze / Tkinter版本)
> 32位和64位版本
>用easygui替换Tkinter(显然easygui需要Tkinter工作)
>检查PATH变量
>重新启动我的电脑(不知道我的预期)
>卸载其他版本的python并修复正确的版本
>将以下内容放在我的编译bat文件中(绝对是正确的路径):

set TCL_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32tcltcl8.6
set TK_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32tcltk8.6

>在我的setup.py中放置以下内容:

options={"build_exe": {"includes": ["tkinter"]}}

>同时:

include_files = [r"C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32DLLstcl86t.dll",
                     r"C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35-32DLLstk86t.dll"]

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

感谢您的帮助,非常感谢.是的,我已经在这个网站上查看过这个问题的每个解决方案.希望有人可以帮助我找到另一个解决方案,因为我的问题似乎是持久的.

找到了解决方案!

我不得不将我的python目录的DLLs文件夹中的tk86t.dll和tcl86t.dll文件复制到我正在尝试编译的main.py的build文件夹中.

这与,有

set TCL_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35tcltcl8.6  
set TK_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython35tcltk8.6

在我的compile.bat的顶部,包括
“include_files”:[“tcl86t.dll”,“tk86t.dll”]
在我的setup.py中的build_exe_options中,似乎已经完成了这个伎俩.

这是我目前的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",)

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

@echo off
set TCL_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32tcltcl8.6
set TK_LIBRARY=C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32tcltk8.6
RD /S /Q "C:UsersVergilTheHuragokDesktopPythonProjectCompiledbin"
mkdir "C:UsersVergilTheHuragokDesktopPythonProjectCompiledbin"
xcopy /s "C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32DLLstcl86t.dll" "C:UsersVergilTheHuragokDesktopPythonProjectCompiledbintcl86t.dll"
xcopy /s "C:UsersVergilTheHuragokAppDataLocalProgramsPythonPython36-32DLLstk86t.dll" "C:UsersVergilTheHuragokDesktopPythonProjectCompiledbintk86t.dll"
cd "C:UsersVergilTheHuragokDesktopPythonProject"
cxfreeze main.py --target-dir "C:UsersVergilTheHuragokDesktopPythonProjectCompiledbin" --target-name "launch.exe"
pause

我找到了这个解决方案here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读