You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用cx_Freeze打包Python程序时出现lief模块logging属性缺失错误

问题描述

我编写了如下setup.py文件:

import sys
import logging
from cx_Freeze import setup, Executable

# Replace 'metadata_gui.py' with the name of your Python script.
target_script = "metadata_gui.py"

# Dependencies (if any). Add other modules or packages as needed.
includes = []
excludes = []
packages = []

# Create the executable.
executables = [Executable(target_script, targetName="metadata")]

# Set up the build options.
build_options = {
    "includes": includes,
    "excludes": excludes,
    "packages": packages,
}

# Run setup.
setup(
    name="metadata",
    version="1.0",
    description="Your description here",
    options={"build_exe": build_options},
    executables=executables,
)

执行命令:

python setup.py build

后出现如下错误:

C:\Users\AM4\dicom\set_up>python setup.py build
Traceback (most recent call last):
  File "setup.py", line 3, in <module>
    from cx_Freeze import setup, Executable
  File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\__init__.py", line 12, in <module>
    from .command.build_exe import BuildEXE as build_exe
  File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\command\build_exe.py", line 14, in <module>
    from ..freezer import Freezer
  File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\freezer.py", line 32, in <module>
    from .parser import ELFParser, Parser, PEParser
  File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\parser.py", line 29, in <module>
    lief.logging.set_level(lief.logging.LOGGING_LEVEL.ERROR)
AttributeError: module 'lief' has no attribute 'logging'
解决方案

这个错误是cx_Freeze与依赖的lief版本不兼容导致的:新版本lief已移除logging模块,但当前cx_Freeze版本仍在调用该旧接口。可通过以下两种方式解决:

  • 降级lief到兼容版本
    执行命令安装最后一个保留logging模块的稳定版本:
pip install lief==0.12.3
  • 升级cx_Freeze到最新版本
    若项目允许,直接更新cx_Freeze以适配新版lief:
pip install --upgrade cx_Freeze

注:操作前建议激活对应的Anaconda环境,确保依赖修改作用于当前项目环境。

内容的提问来源于stack exchange,提问作者Andreia Cristina Maia Oliveira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 11:05:06