How solve ImportError: No module named 'dbus'?
Asked Answered
H

9

23

I have installed anaconda4 on my ubuntu and I have these modules on my Python:

dbus-python (1.2.4)

gi (1.2)

pydbus (0.2)

QtAwesome (0.3.2)
qtconsole (4.2.0)
QtPy (1.0)

sip (4.18)

I tried installing dbus-python (1.2.4) and pydbus (0.2), however, neither of them works!

After testing a simple program in python 3.5.1, an error appeared:

import dbus
system_bus = dbus.SystemBus()

ImportError: No module named 'dbus'

When I use pydbus in Python 2.7.11 and 3.5.1:

from pydbus import SystemBus

bus = SystemBus()
systemd = bus.get(".systemd1")

for unit in systemd.ListUnits():
    print(unit)

I get this error:

ImportError: No module named repository

The only thing that works is this example with PyQT4 which I don't have any tutorial for.

What is the problem? Is it my installation or something else?

Hiers answered 30/5, 2016 at 8:38 Comment(1)
"I've this modules on my python:" - is that under 2.7 or 3.5? Have you compared the two directory trees? More than likely you have not installed everything into both. I suggest you check the environment variables PATH and PYTHONPATH (if it exists) when you do the install.Nonah
S
43

Try this for Python 3.6 32 bit version

pip install dbus-python
Stocktonontees answered 20/9, 2018 at 4:16 Comment(1)
I am using conda and conda install -c conda-forge dbus-python worked for me. Other answers didn't work in a conda environment.Raglan
E
33

I don't know about installing dbus in anaconda but you can install it using apt-get in ubuntu .

sudo apt-get install python-dbus

I tried with pip earlier but that didn't work for me.

Elegancy answered 20/6, 2016 at 16:4 Comment(2)
sudo apt install python3-dbus for python 3Juliajulian
This is for debian based os(ubuntu in your case) as Chetan answered ... but @amit's command gave me Package python-dbus is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source Reprimand
I
5

I encountered same problem while installing notify2 in python3 I was on MacOS 10.12 resolved using

brew install dbus
Illsuited answered 8/11, 2016 at 17:6 Comment(1)
This is for MacOSX (and others) or basically all OS with homebrew installed.Reprimand
U
3

I'm not sure how you installed the modules but this error most likely occurs because the module is not installed or not installed correctly. I would recommend the following for installing a module.

pip install dbus

or since you have anaconda this will also work

conda install dbus

If you are able to access and download the source code for instance on GitHub you can try the following two methods. Navigate to the source code directory then run the following commands in the terminal:

pip install setup.py

or

python setup.py build
python setup.py install

For more on installing packages from source distributions see this page.

Urbanist answered 30/5, 2016 at 8:54 Comment(4)
I've tried pip install dbus, always got this error : Could not find a version that satisfies the requirement dbus (from versions: ) No matching distribution found for dbusHiers
which operation system do you use for dbus programming? you know i'm going crazy right now, why something this simple is giving me so much pain.Hiers
I have actually never used dbus. If you can download the source code you can use the source installation methods I added to the answer.Urbanist
There is no package called dbus in pip. There is a dbus-python which did not install for me on anaconda3 complaining about non-standard prefix.Cenotaph
C
2

I had the same problem when running an application called zeitgeist-explorer, but solved it by installing python2-dbus because the system was using version 3.5 and the application needed the 2 something version. check this post if you are getting an error like this one fix import error no module named dbus

Cocainize answered 16/7, 2016 at 12:55 Comment(0)
M
1

pydbus requires python-gi (or python3-gi in the case of Python 3). And pydbus 0.2 is really outdated, 0.5.1 is the current version.

Mirellamirelle answered 1/6, 2016 at 7:41 Comment(0)
P
1

Just do

sudo apt-get install python-dbus

on debian based os(ubuntu in your case) or

brew install dbus

on MacOSX

Payson answered 29/10, 2017 at 5:2 Comment(1)
Duplicate to this [brew] and this [apt-get]Reprimand
R
0

Try re-installing dbus-python. Also try on another virtual environment.

Reckless answered 19/2, 2020 at 21:54 Comment(2)
This advise seems to have already been given in nearly all of the previous answer to this question.Paleoasiatic
@Brian It was my re-iteration of may be same solution which will give more confidence to the later visitor of the same issue based on my experience. Happy life.Reckless
T
0

I had the same error because I tried to install dbus on Windows and it's not supported:

enter image description here

Telespectroscope answered 29/7 at 11:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.