我试图在 python3 项目中使用 dbus,但是当我尝试导入它时,出现错误:
>>> import dbus
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dbus'
所以我尝试通过确保为我的 python 3.6 安装安装了 dbus 来修复它,但它似乎已经安装了:
$ sudo apt-get install python3-dbus
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-dbus is already the newest version (1.2.0-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
我可以在 python 2.7 中导入 dbus 没有任何问题,但我的 python3 似乎找不到该模块,即使它显示它已经安装。我的 which python3 显示它安装在/usr/local/bin/python3
请您参考如下方法:
您可能会收到此错误,因为 apt-get 安装的模块的路径不在您的 sys.path 中。您可以尝试的一种解决方案是:
import sys
sys.path.insert(0, "/usr/lib/python3/dist-packages")
import dbus
