我写了一个基本程序来跟踪客户名称,车辆,里程和日期,并且还有一个选项供用户选择查看我使用海龟模块绘制的公司徽标。然后我使用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')])
&#34;中的tkinter模块包括&#34;对于我的build_exe,我试图删除并拼写它只是tkinter,我试图把tkinter和turtle,以及每个单独的模块放在&#34; packages&#34;而不是&#34;包括&#34;。我已经尝试了与cx_Freeze文档中的情况相关的每个选项而没有运气。
我发现了另一个与我的问题密切相关的问题:import _tkinter # If this fails your Python may not be configured for Tk这个问题没有答案,而且我的情况有所不同。
我正在运行Windows 10操作系统和Python 3.6.1 此脚本在从Python IDLE
运行时也能正常工作答案 0 :(得分:0)
对于图标,您需要做的是在您的setup.py中,在os.environ部件集基本等于无(base = None)下,然后在可执行文件变量中,就在您放入OilExchange.py之后需要输入一个逗号,比如说base等于base(base = base),再写一个逗号,写入图标并将其设置为等于你的图标目录。这是我的示例executables = [Executable("texteditor.py", base=base, icon="books_logo.ico")]
答案 1 :(得分:-1)
这是一个更全面的澄清版本
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")]