Picamera not working as expected

Hi,

I have been trying to get the rpi camera to work but it seems there’s something wrong with the io.balena.features.kernel-modules label. These are my Dockerfile and docker-compose file:

docker-compose.yml

version: '2.1'

services:
  picture:
build: .
restart: always
privileged: true
labels:
  io.balena.features.kernel-modules: '1'
  io.balena.features.dbus: '1'

Dockerfile

FROM balenalib/raspberry-pi-alpine-python:3.7-3.8

RUN pip install -U pip \
    && READTHEDOCS=True pip install --no-cache-dir picamera

WORKDIR /src
COPY . .
CMD modprobe v4l2_common && python test.py

My test.py file just imports the picamera module.

This will always result in the following error:

19.03.19 23:11:12 (+0100)  test-image  Traceback (most recent call last):
19.03.19 23:11:12 (+0100)  test-image    File "sample.py", line 2, in <module>
19.03.19 23:11:12 (+0100)  test-image      import picamera
19.03.19 23:11:12 (+0100)  test-image    File "/usr/local/lib/python2.7/site-packages/picamera/__init__.py", line 72, in <module>
19.03.19 23:11:12 (+0100)  test-image      from picamera.exc import (
19.03.19 23:11:12 (+0100)  test-image    File "/usr/local/lib/python2.7/site-packages/picamera/exc.py", line 41, in <module>
19.03.19 23:11:12 (+0100)  test-image      import picamera.mmal as mmal
19.03.19 23:11:12 (+0100)  test-image    File "/usr/local/lib/python2.7/site-packages/picamera/mmal.py", line 47, in <module>
19.03.19 23:11:12 (+0100)  test-image      from .bcm_host import VCOS_UNSIGNED
19.03.19 23:11:12 (+0100)  test-image    File "/usr/local/lib/python2.7/site-packages/picamera/bcm_host.py", line 47, in <module>
19.03.19 23:11:12 (+0100)  test-image      _lib = ct.CDLL('libbcm_host.so')
19.03.19 23:11:12 (+0100)  test-image    File "/usr/local/lib/python2.7/ctypes/__init__.py", line 366, in __init__
19.03.19 23:11:12 (+0100)  test-image      self._handle = _dlopen(self._name, mode)
19.03.19 23:11:12 (+0100)  test-image  OSError: libbcm_host.so: cannot open shared object file: No such file or directory

I have tried the example provided on https://github.com/balena-io-projects/balena-rpi-python-picamera and I get the exact same result.

Can anyone look into this? I’m trying this on both a RPi Zero W and a RPi3-B

Thank you.

As a follow up on my previous post, the workaround to get this to work is to use the debian base image instead of the alpine and install libraspberrypi-bin package. Without it seems the shared libraries are not present.

Can someone double check that this example is actually working? https://github.com/balena-io-projects/balena-rpi-python-picamera

thanks,
nelson

Hey!
I (still) got the same problem. The git example is also not working. Did all the configuration (https://www.balena.io/docs/learn/develop/hardware/i2c-and-spi/) and so on but still get the some error. Unfortunately your solution isn’t working either… :frowning: Can’t install libraspberrypi-bin cause its not fount. Maybe this is cause I’m using an raspberry pi 4?

Have you found an other solution to this task?
Thanks a lot!

Thomas

Hi @thomask did you use this project https://github.com/balena-io-projects/balena-rpi-python-picamera and tried to install the libraspberrypi-bin if not can you share your Dockerfile? Can you check if there are any /dev/video* devices present (on host and on the container). Also a thing to try if you are using the balena-rpi-python-picamera project is to change this line https://github.com/balena-io-projects/balena-rpi-python-picamera/blob/8eb2af20befd172943655b12355494dfdd1e1d90/Dockerfile.template#L1 to use a raspberry pi 3 image.

Hi,
I am having the same issues with an rpi4. also tried your last proposal and changed to using the following:
FROM balenalib/raspberrypi3-64-ubuntu-python

Also tried with and without modprobe v4l2_common but that command does not work anyways…