0

我不知道如何将python-nmcli模块集成到我的 Python 脚本中。我似乎从根本上误解了该模块的某些内容。

foo@bar:~ $ pip install python-nmcli
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: python-nmcli in ./.local/lib/python3.7/site-packages (0.1.1)

已安装。

>>> from nmcli import nm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'nm' from 'nmcli' (/home/pi/.local/lib/python3.7/site-packages/nmcli/__init__.py)

这是根据模块文档应该做的第一个。可惜这已经失败了。

>>> import nmcli
>>> print(nmcli)
<module 'nmcli' from '/home/pi/.local/lib/python3.7/site-packages/nmcli/__init__.py'>

好的,至少它已正确加载。

>>> nmcli.dev.status()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'nmcli' has no attribute 'dev'

确实 有一个dev属性,但没有暴露。

>>> from nmcli import NMCommand
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'NMCommand' from 'nmcli' (/home/pi/.local/lib/python3.7/site-packages/nmcli/__init__.py)

为什么我什至不能导入那个类

4

0 回答 0