简体   繁体   中英

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:

>>> 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:

$ 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. My which python3 shows it's installed in /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 . One solution you can try is this:

import sys
sys.path.insert(0, "/usr/lib/python3/dist-packages")
import dbus

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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