我遇到了与许多其他问题相同的问题,但尚未找到有效的解决方案。这是在 Windows 10 64 位、Python 3.6 32 位上。
我试过多次卸载,64 位 Python,安装文件中路径和变量的各种组合。
我确实感到困惑的是,exe 文件的回溯指的是我的 Python 文件夹中的文件路径,而不是可执行文件所在的构建文件夹。我会认为这个 exe 现在应该是“无辜的”python 文件夹的存在?
exe文件的输出
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "main3.py", line 2, in <module>
File "C:\Program Files (x86)\Python36-32\lib\site-packages\appJar\__init__.py", line 2, in <module>
from appJar.appjar import gui
File "C:\Program Files (x86)\Python36-32\lib\site-packages\appJar\appjar.py", line 23, in <module>
from tkinter import *
File "C:\Program Files (x86)\Python36-32\lib\tkinter\__init__.py", line 36, 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.
我的 cx_freeze 安装文件 -
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = r'C:\Program Files (x86)\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files (x86)\Python36-32\tcl\tk8.6'
build_exe_options={
"includes": [],
"packages": ["os","tkinter"],
"include_files" : [r'C:\Program Files (x86)\Python36-32\DLLs\tcl86t.dll',
r'C:\Program Files (x86)\Python36-32\DLLs\tk86t.dll']
}
setup(name = "main" ,
version = "0.1" ,
description = "" ,
options={"build.exe":build_exe_options},
executables = [Executable("main3.py", base=None, targetName="hexml.exe")])
请您参考如下方法:
我终于找到了答案。安装文件中包含文件 tcl86t.dll 和 tk86t.dll 的行由于某种原因没有完成它们的工作。一定是路径格式有问题。
有效的方法是从 Python\Dlls 文件夹中手动复制它们并将它们粘贴到新可执行文件所在的 exe.win 文件夹中。
我后来发现了here获取正确路径的 setup.py 脚本。 V现在很开心。
from cx_Freeze import setup, Executable
import os
import sys
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
options = {
'build_exe': {
'include_files':[
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
],
},
}
setup(name = "main" ,
version = "0.1" ,
description = "" ,
options=options,
executables = [Executable("main3.py", base=None, targetName="hexml.exe")])
