繁体   English   中英

python3即使安装了也无法导入dbus

[英]python3 Can't import dbus even though it's installed

我正在尝试在 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM