1

我正在使用完全更新的 Manjaro 安装(截至 2020 年 8 月 15 日)。在这个项目中使用 python 3.8.3。

我想使用 python 模块 netifaces 来确定我的一个网络接口的 IP 地址。我尝试通过 pip ( sudo pip install netifaces) 和 pacman ( sudo pacman -S python-netifaces) 安装模块。两者都给我 netifaces 版本 0.10.9。但是,当我跑步时

import netifaces
interfaces = netifaces.interfaces()
print(interfaces)

我收到以下错误消息:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-e0d29647271f> in <module>
      1 import netifaces
----> 2 interfaces = netifaces.interfaces()

AttributeError: module 'netifaces' has no attribute 'interfaces'

当我检查dir(netifaces)我得到

['__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__']

然而,它在 python 2.7.18 上运行良好,它按预期返回我的网络接口列表。

它在我的 openSUSE Leap 15.1 安装上也能完美运行。这使用 python 3.6.10 和 netifaces 0.10.9。

我似乎无法在搜索时找到任何类似的问题,更不用说他们的解决方案了。任何帮助将不胜感激。

4

0 回答 0