-1

from picamera import PiCamera gives the following errors in python3.7 on buildroot-generated linux image. Appreciate advice on how to fix. Thanks!

/usr/bin/python3.7: symbol 'mmal_port_pool_create': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_list_push_front': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_list_destroy': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_rational_to_fixed_16_16': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_status_to_string': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_list_push_back': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_list_create': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_list_insert': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_rational_equal': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_list_pop_front': can't resolve symbol
/usr/bin/python3.7: symbol 'mmal_port_type_to_string': can't resolve symbol
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/picamera/__init__.py", line 72, in <module>
    from picamera.exc import (
  File "/usr/lib/python3.7/site-packages/picamera/exc.py", line 41, in <module>
    import picamera.mmal as mmal
  File "/usr/lib/python3.7/site-packages/picamera/mmal.py", line 49, in <module>
    _lib = ct.CDLL('libmmal.so')
  File "/usr/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen() error
Til
  • 5,150
  • 13
  • 26
  • 34
NJS
  • 1
  • 3
  • 1
    Hello and welcome to Stack Overflow, you are expected to show your attempt first, please go through [How to ask](https://stackoverflow.com/help/how-to-ask) and [How to create a minimum complete verifiable example](https://stackoverflow.com/help/mcve) – anand_v.singh Mar 20 '19 at 04:46
  • Sorry if I didn't put it in a code block originally but its just one line of python that causes the above errors: `from picamera import PiCamera` – NJS Mar 21 '19 at 03:15

3 Answers3

0

You need to select the rpi-userland package.

I'm assuming you work on a Raspberry Pi, otherwise picamera is not for you to begin with.

picamera tries to open the libmmal.so shared library. The rpi-userland Buildroot package will download, build and install this library.

If you made a Buildroot package for python-picamera, you should add select BR2_PACKAGE_RPI_USERLAND to its Config.in file, and also copy the dependencies of the rpi-userland package. In the python-picamera.mk file, you should add PYTHON_PICAMERA_DEPENDENCIES += rpi-userland. This will make sure that the package is always selected and built when you enable picamera.

Also, if you have a working python-picamera package, please consider sending it upstream following the contribution guidelines.

If you did not make a Buildroot package for python-picamera, that might be the source of the problem. The picamera package from PyPI is linked with a specific version of libmmal, which may be a different version than the one in Buildroot. This might lead to the errors you see when importing the module.

Arnout
  • 2,927
  • 16
  • 24
  • Thanks for the tips. I had already selected rpi-userland in buildroot and libmmal.so is in /usr/lib but I stil got the above errors. As far as python-picamera package I did not include it in buildroot (I would like to but I am a complete novice with buildroot and makefiles in general so I am doing everything using the menuconfig). Instead I just installed picamera with pip on the pi itself running the linux image I'd made with buildroot. If you'd be willing to walk me through how to include the picamera package in buildroot, I'd appreciate it. – NJS Mar 21 '19 at 15:14
  • Those symbols do exist in libmmal.so AFAICS (to check on your side, you can do `readelf -s output/target/usr/lib/libmmal.so` and verify that all those symbols are there). Maybe there's a binary incompatibility between the package from PyPI and your Buildroot build. – Arnout Mar 26 '19 at 22:32
  • Thanks for the further suggestion. When I run `readelf -s output/target/usr/lib/libmmal.so` on the Ubuntu VM hosting buildroot I see three of those symbols listed: mmal_port_pool_create, mmal_status_to_string and mmal_port_type_to_string but the rest are missing. Does that give any clue? – NJS Apr 01 '19 at 00:59
  • I realize now: if you download the binary from pypi instead of building yourself, it's possible that that binary was linked with a different version of the library that is using different symbols. I think you *have* to build it yourself, i.e. add it as a Buildroot package. It could be sufficient to run `utils/scanpypi picamera` and update `package/Config.in`. – Arnout Apr 01 '19 at 11:09
  • Thanks, those steps seemed to work for adding as a buildroot package but now the make fails when it gets to the install part: – NJS Apr 02 '19 at 04:21
  • `>>> python-picamera 1.13 Installing to target ... setup.py install --no-compile --prefix=/usr --executable=/usr/bin/python --single-version-externally-managed --root=/home/neal/buildroot-2019.02/output/target ... File "setup.py", line 111, in run raise ValueError('Unable to determine if this system is a Raspberry Pi') ... package/pkg-generic.mk:323: recipe for target '/home/neal/buildroot-2019.02/output/build/python-picamera-1.13/.stamp_target_installed' failed make: *** [/home/neal/buildroot-2019.02/output/build/python-picamera-1.13/.stamp_target_installed] Error 1` – NJS Apr 02 '19 at 04:58
  • You'll need to look at picamera's setup.py file to see if there is an option to bypass the "determine if this system is a Raspberry Pi" check. – Arnout Apr 02 '19 at 09:18
  • Thanks for your continued help. I commented out the check in setup.py and the make was successful with the picamera package. Unfortunately `from picamera import PiCamera` still gives the same "can't resolve symbol" errors as I originally posed. :( Any other ideas? – NJS Apr 03 '19 at 00:50
  • Okay, so it's something else... Most of these symbols seem to be provided by `libmmal_util.so` rather than `libmmal.so`. However, `libmmal.so` has a DT_NEEDED entry that should make sure `libmmal_util.so` is loaded automatically... Can you check with `readelf -d output/target/usr/lib/libmmal.so` if that NEEDED entry is there? And also double-check that you have the missing symbols defined (so not UND) in `libmmal_util.so`. – Arnout Apr 03 '19 at 11:56
  • `readelf -d output/target/usr/lib/libmmal.so` returns: `Dynamic section at offset 0x1ee8 contains 30 entries: Tag Type Name/Value ... 0x00000001 (NEEDED) Shared library: [libmmal_util.so] ...` – NJS Apr 03 '19 at 14:49
  • And when I do `readelf -s output/target/usr/lib/libmmal_util.so` I only see mmal_port_pool_create and mmal_list_push_front. They are not UND: ` 40: 000041bc 208 FUNC GLOBAL DEFAULT 8 mmal_port_pool_create 42: 000081bc 80 FUNC GLOBAL DEFAULT 8 mmal_list_push_front` three of them (mmal_port_pool_create, mmal_status_to_string and mmal_port_type_to_string) are in libmmal.so itself (and are also not UDF). Note that mmal_port_pool_create seems to be in both libraries – NJS Apr 03 '19 at 14:57
  • Take into account that readelf truncates long names, so `mmal_rational_to_fixed_16_16` becomes `mmal_rational_to_fixed_16_16`. In my build, it is part of `libmmal_util.so`. – Arnout Apr 03 '19 at 20:47
  • Good point. And I made an even dumber error when I thought most were missing - sorry about that. `readelf -s output/target/usr/lib/libmmal_util.so` returns 200 symbols including all 11 that can't be resolved when I do `from picamera import PiCamera` So what does this all tell you? They are in libmmal_util.so but picamera seems to be looking in libmmal.so? – NJS Apr 04 '19 at 00:07
  • I'm out of ideas :-( It looks like it doesn't automatically load libmmal_util. Could you try editing picamera/mmal.py and add an explicit `ct.CDLL('libmmal_util.so')` before the one of libmmal.so? – Arnout Apr 04 '19 at 08:20
  • Thanks again for trying to help. I added the line `_lib = ct.CDLL('libmmal_util.so')` before `_lib = ct.CDLL('libmmal.so')` and now `from picamera import PiCamera` gives 42 "can't resolve symbol" errors. If that gives you any further clues, please let me know. – NJS Apr 04 '19 at 16:07
  • Okay well thanks again for your efforts. I posted an issue in the Git Hub project, so maybe I'll get a fix from there... – NJS Apr 04 '19 at 23:42
0

FWIW I ended up just using raspistill...

  raspistill_params = (' -n'
  + ' -ISO ' + str(iso)
  + ' -ss ' + str(shutter_speed)
  + ' -mm ' + meter_mode
  + ' -ex ' + exposure_mode
  + ' --ev ' + str(exposure_compensation)
  + ' -awb ' + awb_mode
  + ' -br ' + str(brightness)
  + ' -co ' + str(contrast)
  + ' -sa ' + str(saturation)
  + ' -sh ' + str(sharpness)
  + ' -drc ' + drc_strength
  + ' -rot ' + str(rotation) 
  + ' -q ' + str(quality) 
  + ' -w ' + str(width) 
  + ' -h ' + str(height) 
  + ' -ae ' + str(annotate_text_size) + ',0xff,0x808000 '
  + ' -a "' + annotate_text + '"'
  + ' -x GPS.GPSLatitudeRef=' + exif_lat_ref(latitude)  
  + ' -x GPS.GPSLatitude=' + exif_latlong(latitude)  
  + ' -x GPS.GPSLongitudeRef=' + exif_long_ref(longitude)  
  + ' -x GPS.GPSLongitude=' + exif_latlong(longitude) 
  + ' -o ' + filename
  )

  proc = subprocess.Popen("raspistill " + raspistill_params, shell=True, stdout=subprocess.PIPE)
  ret_val = proc.communicate() 
NJS
  • 1
  • 3
-1
sudo apt-get update
sudo apt-get upgrade

sudo raspi-config

Enable camera and reboot

Bear-K
  • 41
  • 8