python - 使用 cx_Freeze 时出现“ImportError: DLL load failed: The specified module could not be found”,即使添加了 tcl86t.dll 和 tk86t.dll
问题描述
我正在尝试使用 cx_Freeze 5.1.1 将 .py 文件转换为 .exe。但ImportError: DLL load failed
每次尝试运行文件时都会弹出一个。根据此处和此处的建议解决方案,我将 tcl86t.dll 和 tk86t.dll 添加到包含文件列表中。它们出现在构建文件夹中,但错误消息不断弹出。
这是我的 setup.py:
import sys
import os
from cx_Freeze import setup, Executable
os.environ["TCL_LIBRARY"] = r"C:/Users/Name/AppData/Local/Programs/Python/Python36-32/tcl/tcl8.6"
os.environ["TK_LIBRARY"] = r"C:/Users/Name/AppData/Local/Programs/Python/Python36-32/tcl/tk8.6"
base = "Win32GUI" if sys.platform=="win32" else None
build_exe_options = {"packages": ["winsound", "random", "time", "tkinter", "math"],
"include_files": ['tcl86t.dll',
'tk86t.dll']}
setup(
name = "Game",
author = "Name",
description = "game description",
options = {"build_exe": build_exe_options},
executables = [Executable("game.py", base=base)]
)
我正在使用 Python 3.6.3 和 Windows 10。任何帮助将不胜感激!
解决方案
在cx_Freeze
5.1.1 版本中,包含的模块位于lib
构建目录的子目录中。和DLL 显然tcl86t.dll
也tk86t.dll
需要移到那里。
您可以通过对setup.py
脚本进行以下修改来做到这一点:
build_exe_options = {"packages": ["winsound", "random", "time", "tkinter", "math"],
"include_files": [('tcl86t.dll', os.path.join('lib', 'tcl86t.dll')),
('tk86t.dll', os.path.join('lib', 'tk86t.dll'))]}
推荐阅读
- c# - 有没有办法从代码中获取完整的 URL 到其他控制器方法?
- mysql - MySQL重组Union All查询,因此它只命中数据库一次
- jenkins - Jenkins管道触发文件
- django - 在这种情况下我应该使用抽象模型吗?
- c# - 如何知道与流中的提要发生的交互?
- android - 位图太大。都试过了
- angular - 错误类型错误:无法读取未定义的属性“stateName”
- .net - parent.exe崩溃时如何立即取回控件?
- python-3.x - numpy(Python)np.size(a1)和a1.size()中的size函数用法有什么区别
- node.js - standard_init_linux.go:190:exec 用户进程导致“exec 格式错误”命令“/bin/sh -c npm install”返回非零代码:1