使用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.
有些事情需要注意:
>我想使用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:\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
>在我的setup.py中放置以下内容:
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()中)
感谢您的帮助,非常感谢.是的,我已经在这个网站上查看过这个问题的每个解决方案.希望有人可以帮助我找到另一个解决方案,因为我的问题似乎是持久的.
找到了解决方案!
原文链接:https://www.f2er.com/windows/364298.html我不得不将我的python目录的DLLs文件夹中的tk86t.dll和tcl86t.dll文件复制到我正在尝试编译的main.py的build文件夹中.
这与,有
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”]
在我的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:\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