22

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?

Moon Cheesez
  • 2,489
  • 3
  • 24
  • 38
B nM
  • 369
  • 1
  • 5
  • 17
  • "*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. – cdarke May 30 '16 at 08:54

8 Answers8

40

Try this for Python 3.6 32 bit version

pip install dbus-python
Arun K
  • 868
  • 10
  • 17
  • 2
    I am using `conda` and `conda install -c conda-forge dbus-python` worked for me. Other answers didn't work in a `conda` environment. – Burak Kaymakci Sep 12 '20 at 05:41
31

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.

Amit Chahar
  • 2,519
  • 3
  • 18
  • 23
  • 18
    `sudo apt install python3-dbus` for python 3 – Smarty77 Feb 19 '18 at 11:19
  • This is for debian based os(ubuntu in your case) [as Chetan answered](https://stackoverflow.com/a/46997001/4575793) ... 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 ` – Cadoiz Feb 01 '23 at 13:44
5

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

brew install dbus
azhar22k
  • 4,765
  • 4
  • 21
  • 24
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.

Neill Herbst
  • 2,072
  • 1
  • 13
  • 23
  • 3
    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 dbus – B nM May 30 '16 at 11:46
  • 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. – B nM May 30 '16 at 11:47
  • 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. – Neill Herbst May 30 '16 at 15:03
  • 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`. – cnvzmxcvmcx Dec 09 '16 at 18:17
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

Mauricio
  • 433
  • 5
  • 15
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.

LEW21
  • 161
  • 4
0

Just do

sudo apt-get install python-dbus

on debian based os(ubuntu in your case) or

brew install dbus

on MacOSX

Chetan Malhotra
  • 457
  • 6
  • 6
  • Duplicate to [this \[`brew`\]](https://stackoverflow.com/a/40492625/4575793) and [this \[`apt-get`\]](https://stackoverflow.com/a/37927053/4575793) – Cadoiz Feb 01 '23 at 13:43
-1

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

Garry S
  • 79
  • 9
  • This advise seems to have already been given in nearly all of the previous answer to this question. – Brian61354270 Feb 19 '20 at 22:18
  • @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. – Garry S Feb 21 '20 at 15:28