简体   繁体   English

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

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

I'm trying to use dbus in a python3 project, but when I try to import it, I get an error:我正在尝试在 python3 项目中使用 dbus,但是当我尝试导入它时,出现错误:

>>> import dbus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dbus'

So I tried to fix it by making sure dbus is installed for my python 3.6 installation but it seems to already be installed:所以我试图通过确保为我的 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.

I'm able to import dbus in python 2.7 without any problems, but my python3 can't seem to find the module even though it shows that it's already installed.我可以在 python 2.7 中导入 dbus 没有任何问题,但我的 python3 似乎无法找到该模块,即使它显示它已经安装。 My which python3 shows it's installed in /usr/local/bin/python3我的which python3显示它安装在 /usr/local/bin/python3

You are probably getting this error because the path to the module installed by apt-get is not in your sys.path .您可能会收到此错误,因为apt-get安装的模块的路径不在您的sys.path One solution you can try is this:您可以尝试的一种解决方案是:

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