【发布时间】:2025-12-20 06:20:22
【问题描述】:
我想第一次使用 CxFreeze。我还想实现日志记录模块,它是 Python 3.6 中的标准模块。 我安装了最新版本的 CxFreeze(在 5.1.1 中)
这是我的代码!
from cx_Freeze import setup, Executable
import os,sys, logging
base = None
executables = [Executable("utt.py", base=base)]
packages = ["idna"]
includes = ["logging"]
options = {
'build_exe': {
'packages':packages,
'includes':includes
},
}
# On appelle la fonction setup
setup(
name = "Import ",
version = "1",
description = "Gestion rapide",
options = options,
executables = executables
)
这里是错误信息
C:\Python\Python36\Scripts>C:\Python\Python36\Scripts\build\exe.win-amd64-3.6\utt.exe
2018-08-21 17:43:46.354712
2018-08-21-17-43-46
Traceback (most recent call last):
File "C:\Python\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "C:\Python\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "utt.py", line 16, in <module>
logging.basicConfig(filename=fileDate,level=logging.DEBUG,format='%(asctime)s %(levelname)s-8s %(message)s')
NameError: name 'logging' is not defined
拜托,我不明白为什么我的 mdoule 没有定义。我尝试了 Inclues 和 Packages 属性,甚至使用 include_files 属性导入日志库。
问候。
【问题讨论】:
-
脚本不在可执行文件中时是否运行?这是 python 错误,不是 cxfreeze 错误。
-
告诉我们
utt.py。或者,更好的是,向我们展示minimal reproducible example,只需提供足以重现问题的代码即可。 -
可能,您忘记在您的
utt.py中导入logging?另外我认为你不应该在included中指定logging,因为它是一个标准模块,它总是被隐式包含。
标签: python logging module undefined