0

I have a raspberry pi4 and i was trying to capture the camera output. Here's the code:


from picamera import PiCamera

camera = PiCamera()
camera.start_preview(alpha=192)

on interpreting this gives me following error:

Traceback (most recent call last):
  File "/home/user/Documents/codes/cam.py", line 1, in <module>
    from picamera import PiCamera
  File "/home/user/pyvenv/lib/python3.11/site-packages/picamera/__init__.py", line 72, in <module>
    from picamera.exc import (
  File "/home/user/pyvenv/lib/python3.11/site-packages/picamera/exc.py", line 41, in <module>
    import picamera.mmal as mmal
  File "/home/user/pyvenv/lib/python3.11/site-packages/picamera/mmal.py", line 49, in <module>
    _lib = ct.CDLL('libmmal.so')
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ctypes/__init__.py", line 376, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: libmmal.so: cannot open shared object file: No such file or directory

I checked for this file from dpkg but it showed no results:

$ sudo ldconfig -p | grep "mmal"
$

I have updated the system from both apt and rpi-update but it didn't fix the issue. How do I solve this issue?

System info:

$ uname -a
Linux raspberrypi 6.6.22-v8+ #1747 SMP PREEMPT Wed Mar 27 17:04:50 GMT 2024 aarch64 GNU/Linux
1
  • Sometimes, the installation might have been incomplete or corrupted. Reinstalling the library might help.
    – liaifat85
    Apr 5 at 15:33

1 Answer 1

1

I assume that is Raspberry Pi OS Bookworm that you are using.

You should be using picamera2, picamera is out of date.

https://github.com/raspberrypi/picamera2/blob/main/examples/capture_jpeg.py

#!/usr/bin/python3

# Capture a JPEG while still running in the preview mode. When you
# capture to a file, the return value is the metadata for that image.

import time

from picamera2 import Picamera2, Preview

picam2 = Picamera2()

preview_config = picam2.create_preview_configuration(main={"size": (800, 600)})
picam2.configure(preview_config)

picam2.start_preview(Preview.QTGL)

picam2.start()
time.sleep(2)

metadata = picam2.capture_file("test.jpg")
print(metadata)

picam2.close()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.