【问题标题】:cx_Freeze Import Error: DLL load failed: The specified module could not be foundcx_Freeze Import Error: DLL load failed: 找不到指定的模块
【发布时间】:2017-11-05 03:33:35
【问题描述】:

我编写了一个基本程序来跟踪客户姓名、车辆、里程和日期,它还有一个选项供用户选择查看我使用海龟模块绘制的公司徽标。然后我使用 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 以及每个单独的模块放在“包”而不是“包含”中。我已经尝试了 cx_Freeze 文档中与我的情况相关的所有选项,但没有成功。

我发现了另一个与我的问题密切相关的问题:import _tkinter # If this fails your Python may not be configured for Tk 这个问题没有答案,我的问题有些不同。

我正在运行 Windows 10 操作系统和 Python 3.6.1 当从 Python IDLE 运行时,该脚本也可以工作

【问题讨论】:

    标签: python python-3.x cmd cx-freeze python-3.6


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这里有一个更完整的版本来说明

      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")]
      

      【讨论】:

      • 您应该将此添加到您的原始答案中,而不是发布新答案
      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 2015-04-22
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2018-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多