繁体   English   中英

cx_Freeze导入错误:DLL加载失败:找不到指定的模块

[英]cx_Freeze Import Error: DLL load failed: The specified module could not be found

我编写了一个基本程序来跟踪客户名称,车辆,里程和日期,它还提供了一个选项供用户选择查看我使用turtle模块绘制的公司徽标。 然后,我使用cx_freeze将其冻结为可执行文件,然后所有内容冻结,并创建了包含所有必需文件和文件夹以及可执行文件的构建文件,但是当我运行.exe文件时,无法选择查看公司的选项。商标。 在CMD中运行该错误时,我仍然收到此错误:

C:\Users\hdaug\Documents\Holden's Personal\PythonPrograms\CX\build\exe.win-amd64-3.6>OilChangeEx.exe
At Holden's Oil Change we use our custom built Python program to keep track of customer records and to display our company logo!!
Select and option from the menu!
1   Current Customers
2   New Customers
3   Company Logo
4   Quit
Select an option: 3
Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Program Files\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "OilChangeEx.py", line 282, in <module>
  File "OilChangeEx.py", line 56, in main
  File "OilChangeEx.py", line 77, in commandChoice
  File "OilChangeEx.py", line 176, in Turt
  File "C:\Program Files\Python36\lib\turtle.py", line 107, in <module>
    import tkinter as TK
  File "C:\Program Files\Python36\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.

错误的顶部是我的代码的实际运行,您可以看到4个选项。 除#3以外,所有这些工作都可以。

我已经检查了tkinter文档和cx_Freeze文档,但找不到我做错的任何事情。 这是我用来构建可执行文件的setup.py文件:

from cx_Freeze import setup, Executable
import os

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python36\tcl\tk8.6'

build_exe_options = {"includes": ["turtle","_tkinter"]}

setup(name='OilChange',
      version='0.1',
      description='OilChangeRecords',
      options = {"build_exe": build_exe_options},
      executables = [Executable('OilChangeEx.py')])

我的build_exe的“包含”中的tkinter模块,我试图将其删除并拼写为tkinter,我试图将tkinter和turtle以及每个单独的模块都放入“包”中,而不是“ includes”中。 我在cx_Freeze文档中尝试了所有与我的情况有关的选项,但没有走运。

我发现了另一个与我的问题密切相关的问题: import _tkinter#如果失败,则可能没有为Tk配置Python 。该问题没有答案,我的情况有所不同。

我正在运行Windows 10 OS和Python 3.6.1,并且从Python IDLE运行时,脚本也可以正常工作

对于图标,您需要做的是在setup.py中,在os.environ部件下,将base设置为none(base = None),然后在可执行文件变量中,将OilExchange.py放进去。一个逗号,例如说base等于base(base = base),放另一个逗号,写图标,并将其设置为等于图标目录。 这是我的示例executables = [Executable("texteditor.py", base=base, icon="books_logo.ico")]

这是一个更完整的版本以供澄清

from cx_Freeze import setup, Executable
import sys
import os

os.environ['TCL_LIBRARY'] = r'C:\Program Files\Python36\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Program Files\Python36\tcl\tk8.6'

# Dependencies are automatically detected, but it might need fine tuning.
#build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'
setup(
    name = "VBtEditor",
    options = {"build_exe": {"packages":["tkinter", "os", "cx_Freeze"], "include_files": ["books_logo.ico"]}},
    version = "0.01",
    description = "Professional text editor part of the VIRTUAL BUREAU",
    executables = [Executable("texteditor.py", base=base,    icon="books_logo.ico")]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM