[英]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: 有些事情需要注意:
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:
包括但不仅限于:
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"]}}
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
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
. 可执行文件需要位于同一目录中(因此它不一定是独立的),但它与
pandas
和numpy
一起运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.