pyudev 类型对象 'Context' 没有属性 '_libudev'
pyudev type object 'Context' has no attribute '_libudev'
我在 Debian GNU/Linux 8.7 (jessie)
上使用 pyudev 库和 python2.7
来检测 USB 设备,如下所示:
import sys
import pyudev
def main():
os = canary.helpers.get_platform_system()
if os.lower() == "linux":
print("linux")
context = pyudev.Context
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(device_type='usb')
elif os.lower() == 'darwin': # actually OS X
print("OS X is currently not supported, if you would like to add support make a pull request. Aborting...")
sys.exit()
elif os.lower() == 'windows':
print("Windows is currently not supported, if you would like to add support make a pull request. Aborting...")
sys.exit()
else:
print("Unknown operating system. Aborting...")
sys.exit()
if __name__ == "__main__":
main()
如多个示例所示 - 但是当我 运行 代码时出现以下错误:
/usr/bin/python2.7 /home/marvin/src/usb_canary/usb_canary.py
linux
Traceback (most recent call last):
File "/home/marvin/src/usb_canary/usb_canary.py", line 45, in <module>
main()
File "/home/marvin/src/usb_canary/usb_canary.py", line 30, in main
monitor = pyudev.Monitor.from_netlink(context)
File "/usr/local/lib/python2.7/dist-packages/pyudev/monitor.py", line 121, in from_netlink
monitor = context._libudev.udev_monitor_new_from_netlink(
AttributeError: type object 'Context' has no attribute '_libudev'
最初通过 pip 安装 pyudev
后,我忘记确保安装了 libudev-dev
,所以我安装了 libudev-dev
,卸载了 pyudev
,然后通过 pip 重新安装,但是错误仍然存在。
我目前运行宁libudev-dev
版本215
谁能告诉我为什么会出现这个错误以及如何修复它?我查看了他们的 Github 问题,但没有发现任何人遇到同样的问题我也查看了他们的 Read the Docs wiki,但仍然没有运气。
看来需要实例化Context才能使用,所以加上括号:
context = pyudev.Context()
然后 filter_by
需要另一个输入参数。但是,如果您查看文档,您可能会弄明白。
我在 Debian GNU/Linux 8.7 (jessie)
上使用 pyudev 库和 python2.7
来检测 USB 设备,如下所示:
import sys
import pyudev
def main():
os = canary.helpers.get_platform_system()
if os.lower() == "linux":
print("linux")
context = pyudev.Context
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(device_type='usb')
elif os.lower() == 'darwin': # actually OS X
print("OS X is currently not supported, if you would like to add support make a pull request. Aborting...")
sys.exit()
elif os.lower() == 'windows':
print("Windows is currently not supported, if you would like to add support make a pull request. Aborting...")
sys.exit()
else:
print("Unknown operating system. Aborting...")
sys.exit()
if __name__ == "__main__":
main()
如多个示例所示 - 但是当我 运行 代码时出现以下错误:
/usr/bin/python2.7 /home/marvin/src/usb_canary/usb_canary.py
linux
Traceback (most recent call last):
File "/home/marvin/src/usb_canary/usb_canary.py", line 45, in <module>
main()
File "/home/marvin/src/usb_canary/usb_canary.py", line 30, in main
monitor = pyudev.Monitor.from_netlink(context)
File "/usr/local/lib/python2.7/dist-packages/pyudev/monitor.py", line 121, in from_netlink
monitor = context._libudev.udev_monitor_new_from_netlink(
AttributeError: type object 'Context' has no attribute '_libudev'
最初通过 pip 安装 pyudev
后,我忘记确保安装了 libudev-dev
,所以我安装了 libudev-dev
,卸载了 pyudev
,然后通过 pip 重新安装,但是错误仍然存在。
我目前运行宁libudev-dev
版本215
谁能告诉我为什么会出现这个错误以及如何修复它?我查看了他们的 Github 问题,但没有发现任何人遇到同样的问题我也查看了他们的 Read the Docs wiki,但仍然没有运气。
看来需要实例化Context才能使用,所以加上括号:
context = pyudev.Context()
然后 filter_by
需要另一个输入参数。但是,如果您查看文档,您可能会弄明白。