jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
362 stars 59 forks source link

ImportError: No module named '_widget' #55

Closed Tornbloj closed 5 years ago

Tornbloj commented 6 years ago

Installed using pip3.

When running:

pi@raspberrypi:/usr/local/share/python-gphoto2/examples $ python3 camera-summary.py

I get the following error:

Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/gphoto2/widget.py", line 28, in swig_import_helper return importlib.import_module(mname) File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 986, in _gcd_import File "", line 969, in _find_and_load File "", line 958, in _find_and_load_unlocked File "", line 666, in _load_unlocked File "", line 577, in module_from_spec File "", line 914, in create_module File "", line 222, in _call_with_frames_removed ImportError: libgphoto2_port.so.10: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "list-cameras.py", line 25, in import gphoto2 as gp File "/usr/local/lib/python3.5/dist-packages/gphoto2/init.py", line 17, in from gphoto2.abilities_list import * File "/usr/local/lib/python3.5/dist-packages/gphoto2/abilities_list.py", line 9, in import gphoto2.camera File "/usr/local/lib/python3.5/dist-packages/gphoto2/camera.py", line 10, in import gphoto2.context File "/usr/local/lib/python3.5/dist-packages/gphoto2/context.py", line 11, in import gphoto2.file File "/usr/local/lib/python3.5/dist-packages/gphoto2/file.py", line 12, in import gphoto2.filesys File "/usr/local/lib/python3.5/dist-packages/gphoto2/filesys.py", line 13, in import gphoto2.list File "/usr/local/lib/python3.5/dist-packages/gphoto2/list.py", line 14, in import gphoto2.port_info_list File "/usr/local/lib/python3.5/dist-packages/gphoto2/port_info_list.py", line 15, in import gphoto2.port_log File "/usr/local/lib/python3.5/dist-packages/gphoto2/port_log.py", line 16, in import gphoto2.result File "/usr/local/lib/python3.5/dist-packages/gphoto2/result.py", line 17, in import gphoto2.version File "/usr/local/lib/python3.5/dist-packages/gphoto2/version.py", line 18, in import gphoto2.widget File "/usr/local/lib/python3.5/dist-packages/gphoto2/widget.py", line 31, in _widget = swig_import_helper() File "/usr/local/lib/python3.5/dist-packages/gphoto2/widget.py", line 30, in swig_import_helper return importlib.import_module('_widget') File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named '_widget'

Have any idea of the reason?

jim-easterbrook commented 6 years ago

I suspect this is a similar problem to issue #48. How have you installed libgphoto2?

Tornbloj commented 6 years ago

Yes it is installed. Maybe i've missed something?

I followed the steps described in issue #48

What i can see is that libgphoto2_port.so.10 is missing. Might this be the problem? How do fix this?

gphoto2 pi@raspberrypi:/usr/bin $ ldd gphoto2 /usr/lib/arm-linux-gnueabihf/libarmmem.so (0xb6ebb000) libgphoto2.so.6 => /usr/lib/arm-linux-gnueabihf/libgphoto2.so.6 (0xb6e14000) libgphoto2_port.so.12 => /usr/lib/arm-linux-gnueabihf/libgphoto2_port.so.12 (0xb6dfa000) libcdk.so.5 => /usr/lib/arm-linux-gnueabihf/libcdk.so.5 (0xb6db8000) libncurses.so.5 => /lib/arm-linux-gnueabihf/libncurses.so.5 (0xb6d8c000) libaa.so.1 => /usr/lib/arm-linux-gnueabihf/libaa.so.1 (0xb6d62000) libjpeg.so.62 => /usr/lib/arm-linux-gnueabihf/libjpeg.so.62 (0xb6d1c000) libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6cf3000) libexif.so.12 => /usr/lib/arm-linux-gnueabihf/libexif.so.12 (0xb6cb0000) libreadline.so.7 => /lib/arm-linux-gnueabihf/libreadline.so.7 (0xb6c64000) libpopt.so.0 => /lib/arm-linux-gnueabihf/libpopt.so.0 (0xb6c49000) libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6bca000) libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6a8b000) /lib/ld-linux-armhf.so.3 (0xb6f02000) libltdl.so.7 => /usr/lib/arm-linux-gnueabihf/libltdl.so.7 (0xb6a73000) libtinfo.so.5 => /lib/arm-linux-gnueabihf/libtinfo.so.5 (0xb6a44000) libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6a31000) libslang.so.2 => /lib/arm-linux-gnueabihf/libslang.so.2 (0xb682e000) libX11.so.6 => /usr/lib/arm-linux-gnueabihf/libX11.so.6 (0xb670b000) libgpm.so.2 => /usr/lib/arm-linux-gnueabihf/libgpm.so.2 (0xb66f6000) libxcb.so.1 => /usr/lib/arm-linux-gnueabihf/libxcb.so.1 (0xb66c7000) libXau.so.6 => /usr/lib/arm-linux-gnueabihf/libXau.so.6 (0xb66bc000) libXdmcp.so.6 => /usr/lib/arm-linux-gnueabihf/libXdmcp.so.6 (0xb66a7000) libbsd.so.0 => /lib/arm-linux-gnueabihf/libbsd.so.0 (0xb667e000)

_camera.so pi@raspberrypi:/usr/local/lib/python3.5/dist-packages/gphoto2 $ ldd _camera.cpython-35m-arm-linux-gnueabihf.so /usr/lib/arm-linux-gnueabihf/libarmmem.so (0xb6f48000) libgphoto2.so.6 => /usr/lib/arm-linux-gnueabihf/libgphoto2.so.6 (0xb6ea1000) libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6e22000) libgphoto2_port.so.10 => not found libexif.so.12 => /usr/lib/arm-linux-gnueabihf/libexif.so.12 (0xb6ddf000) libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6db6000) libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6c77000) /lib/ld-linux-armhf.so.3 (0xb6f90000) libgphoto2_port.so.12 => /usr/lib/arm-linux-gnueabihf/libgphoto2_port.so.12 (0xb6c5d000) libltdl.so.7 => /usr/lib/arm-linux-gnueabihf/libltdl.so.7 (0xb6c45000) libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6c32000)

Update: Ran: sudo ldconfig and it seems to work. Next problem occurs when i am trying to run the test file:

pi@raspberrypi:/usr/local/share/python-gphoto2/examples $ sudo python3 camera-summary.py Summary

Traceback (most recent call last): File "camera-summary.py", line 59, in sys.exit(main()) File "camera-summary.py", line 36, in main print(text.text) UnicodeEncodeError: 'utf-8' codec can't encode character '\udcf6' in position 77: surrogates not allowed

jim-easterbrook commented 6 years ago

The ldd output shows that gphoto2 was compiled with libgphoto2_port.so.12 but python-gphoto2 was compiled (i.e. installed) with libgphoto2_port.so.10. The usual cure for this is to reinstall, as described in the README. https://github.com/jim-easterbrook/python-gphoto2#reinstalling

The camera-summary error suggests your camera is not using utf-8 encoding for non-ASCII characters. You could try changing line 36 to print(text.text.decode('utf8','replace'))

jim-easterbrook commented 6 years ago

I've found out a bit more about this "surrogate" thing. You should be able to retrieve the original bytes by using text.text.encode('utf-8', errors='surrogateescape'). See http://www.swig.org/Doc3.0/Python.html#Python_nn77 for more info.