python-dbus not working/not available

Hi,

So I’m trying to make some DBUS call in one of my containers. I’m building the image using the balenalib alpine image with python, as seen from the below snippet:

FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine-python:run

There aren’t any issues calling Python to run Python scripts, until I try to run a script using dbus via import dbus in the Python script. I’m following the official balena docs for accessing dbus via python, found here: Network Setup on balenaOS - Balena Documentation. When I try to run an example, the build goes fine but I get the following error when the image is downloaded to the device and Balena tries to run the script:

Traceback (most recent call last):
 myproject-initialize    File "/myproject/networkscript.py", line 2, in <module>
 myporject-initialize      import dbus
 myproject-initialize  ModuleNotFoundError: No module named 'dbus'

As can be seen, the image doesn’t see the dbus module. I have tried multiple workarounds for this, including:

  • Using install_packages to install python-dbus
  • Using the ubuntu image with Python
  • Manually apt-get installing python-dbus within the Ubuntu image

For those package management workarounds, it reports that there’s no package named python-dbus, while using the ubuntu image which should already have the Python dbus module, it reports the same error.

As far as I can see I’m directly following the balena documentation, what’s going on here?

1 Like

Hello, I tested FROM balenalib/%%BALENA_MACHINE_NAME%%-ubuntu-python:3.9-focal-build and was able to import dbus with Python. (on a Raspberry Pi 3b+) I would have to check but perhaps dbus is not included on an Alpine image. Note that I’m using the “build” variant of the base image. Also, note the environment variable (or label needed if using multiple containers) here: Communicate outside the container - Balena Documentation
Which device type are you using?

1 Like