25

I am running an application in a virtual environment that needs access to DBus (to interact with the Network Manager, mainly).

I tried to install Dbus-Python with easyinstall and pip, but both fail.

When I try to do this:

(myvirtualenv)borrajax@borrajax-computer:~/Documents/Projects/VirtualEnvs/current_env$ bin/pip install dbus-python

Pip yells at me with:

Downloading/unpacking dbus-python
  Downloading dbus-python-1.1.1.tar.gz (596kB): 596kB downloaded
  Running setup.py egg_info for package dbus-python
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
    IOError: [Errno 2] No such file or directory: '/home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python/setup.py'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

IOError: [Errno 2] No such file or directory: '/home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python/setup.py'

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python
Storing complete log in /home/borrajax/.pip/pip.log

I have had some issues with the python dbus bindings and their "accessibility" from my Python modules in the past, so I don't really know what may be the best way to set Dbus-Python in a virtual environment. Has anyone successfully achieved this? Or does anyone have an idea on how to do this?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Savir
  • 17,568
  • 15
  • 82
  • 136

7 Answers7

23

Go to your Venv follow this 2 steps :

sudo apt-get install libdbus-glib-1-dev libdbus-1-dev

pip install dbus-python

verify with:

pip freeze

if installed properly you will see: dbus-python==1.2.8

vvvvv
  • 25,404
  • 19
  • 49
  • 81
cryptoKTM
  • 2,593
  • 22
  • 21
20

My suggestion is to install the system package for the Python DBUS bindings and then create the virtualenv with the --system-site-packages command line option to enable access to the system-wide Python packages (including the dbus package) from the activated virtualenv. For example on Debian/Ubuntu (or a derived distribution):

$ sudo apt-get install python-dbus
$ virtualenv --system-site-packages dbus-venv

To use the built in Python 3 venv module instead of virtualenv:

$ sudo apt-get install python-dbus
$ sudo apt-get install python3-venv
$ python3 -m venv --system-site-packages my_venv
phoenix
  • 7,988
  • 6
  • 39
  • 45
Pedro Romano
  • 10,973
  • 4
  • 46
  • 50
15

When pip tries to install a package, it looks for setup.py, which dbus-python doesn't have, so you'll have to download the source and compile it manually. Shouldn't be too hard:

PYTHON=python3.3 ./configure --prefix=/tmp/dbus-python
make
make install

then you can move the compiled files to your virtualenv.


edit: starting with dbus-python-1.2.2 (released 2016-02-22) dbus-python has a setup.py, so pip should be able to install it

mata
  • 67,110
  • 10
  • 163
  • 162
10

Another workaround is to just manually copy the dbus files/libraries directly to your virtualenv:

cp -r /usr/lib/pythonX.X/{site or dist}-packages/dbus myvirtenv/usr/lib/pythonX.X/site-packages/    
cp -r /usr/lib/pythonX.X/{site or dist}-packages/_dbus_*.so myvirtenv/usr/lib/pythonX.X/site-packages/
Tisho
  • 8,320
  • 6
  • 44
  • 52
  • 2
    I like this idea as a lot of systems are going to have dbus-python due to internally used scripts and it can work well with the virtualenvwrapper `postmkvirtualenv` script. – Tatsh Jul 12 '14 at 20:17
  • While this solution is not exactly what I would characterized as perfectly clean, I like it for simplicity. Upvoting. :-) – Drachenfels Jan 12 '15 at 22:35
7

The OP appears to have opened a ticket on freedesktop.org for this, which remains open; however there is a patch attached to that ticket that could be applied to most any version of python-dbus and then repackaged as a new tarball.

Alex Dupuy
  • 5,984
  • 3
  • 39
  • 35
3

@TheMeaningfulEngineer thank so much, i have being having a few problem to install dbus through pip and that was what i needed i hope you have a good day wherever you are ;)

to check if there is in local - sudo apt list --installed | grep package-name

sudo apt-get install libdbus-glib-1-dev libdbus-1-dev

and after this line I did install dbus and networkmanager without any errors

This is exactly what I did, and before that I checked out all my dbus version and networkmanager after do what @TheMeaningfulEngineer said is working.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
  • (This post does not seem to provide a [quality answer](https://stackoverflow.com/help/how-to-answer) to the question. Please either edit your answer, or just post it as a comment to the question). – sɐunıɔןɐqɐp Jun 22 '18 at 07:53
0

For Python as dbus-python is now obsolete, you should be using pydbus:


pip install pydbus

This have worked for me.

  • is it really obsolete? if you look at the release note, you'll see more recent releases than pydbus: https://dbus.freedesktop.org/doc/dbus-python/news.html – Joël Esponde Jan 11 '20 at 23:26