Skip to main content
 首页 » 编程设计

Python::AttributeError: 'module' 对象没有属性 'interfaces'

2024年10月25日10bhlsheji

我从 github 下载了一个 python 项目:

使用ubuntu的接口(interface)文件。 问题是当我尝试按照自述文件所述使用模块时,我得到了这个:

Traceback (most recent call last): 
  File "./ss.py", line 7, in <module> 
    adapters = debinterface.interfaces() 
AttributeError: 'module' object has no attribute 'interfaces' 

我的 ss.py 脚本是:

#!/usr/bin/python 
 
import debinterface 
import sys 
sys.path.append("/home/ed/Downloads/netpy/") 
sys.path.append("/home/ed/Downloads/netpy/debinterface/") 
adapters = debinterface.interfaces() 

我在 "/home/ed/Downloads/netpy/" 中运行此脚本,该脚本由 "debinterface" 组成。我不得不说我在没有 "sys.path.append" 的情况下尝试了该脚本,但没有任何改变,即使我将模块名称 "debinterface" 更改为 "debeh " 但同样也没有任何改变。

我的问题是什么?

请您参考如下方法:

对我来说,这看起来像是文档或包代码中的错误。你可以使用

from debinterface.interfaces import interfaces 

然后用

引用你的 interface类
adapters = interfaces() 

或者编辑debinterface/__init__.py,在导入debinterface包时,为您导入interface模块。添加行

from interfaces import interfaces 

到 __init__.py 文件。