使用cx冻结时,即使添加了tcl86t.DLL和tk86t.DLL,也获取“ImportError:DLL加载失败:找不到指定的模块”

2024-10-04 01:34:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图使用cx\u Freeze 5.1.1将.py文件转换为.exe,但每次尝试运行该文件时都会弹出一个ImportError: DLL load failed。基于建议的解决方案 here和{a2},我将tcl86t.dll和tk86t.dll添加到包含的文件列表中。它们出现在构建文件夹中,但错误消息不断弹出。在

这是我的设置.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)]
)

我使用的是python3.6.3和windows10。任何帮助将不胜感激!在


Tags: 文件namepyimportbuildbaseossys
1条回答
网友
1楼 · 发布于 2024-10-04 01:34:29

cx_Freeze版本5.1.1中,包含的模块位于构建目录的子目录lib中。tcl86t.dll和{}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'))]}

相关问题 更多 >