Skip to main content
 首页 » 编程设计

python之从实用程序导入配置--ImportError : cannot import name 'Config'

2025年01月19日8linjiqin

在 Python 3.5 中,我收到以下导入错误:

ImportError: cannot import name 'Config' 

当我尝试

from utils import Config 

我已经检查过包 utils 是“管道”的。我很好奇,因为几个月前我尝试从 utils 导入 Config 时没问题。

请您参考如下方法:

这是因为utils包中没有Config模块。

如果您在 import utils 之后在 python shell 中尝试 help("utils"),您会注意到 utils 具有这些模块 -

bool 值、日期、字典、枚举、列表、数学和对象,但不是Config。

根据 this doc(虽然已经过时),Config 由 from config import Config 使用。您可能想尝试 pip install config 并查看它是否适用于您的 python 版本。

如果它不起作用,您可以随时使用 configparser。