jim-easterbrook / python-gphoto2

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

NameError: name 'GP_ERROR_CANCEL' is not defined #46

Closed BeebBenjamin closed 6 years ago

BeebBenjamin commented 6 years ago

Using this example below:

import gphoto2 as gp context = gp.Context() camera = gp.Camera() camera.init(context) text = camera.get_summary(context) print('Summary') print('=======') print(str(text)) camera.exit(context)

I get the following errors:

File "libgphoto_example.py", line 1, in import gphoto2 as gp File "/usr/local/lib/python2.7/dist-packages/gphoto2/init.py", line 17, in from gphoto2.abilities_list import * File "/usr/local/lib/python2.7/dist-packages/gphoto2/abilities_list.py", line 86, in import gphoto2.camera File "/usr/local/lib/python2.7/dist-packages/gphoto2/camera.py", line 87, in import gphoto2.context File "/usr/local/lib/python2.7/dist-packages/gphoto2/context.py", line 88, in import gphoto2.file File "/usr/local/lib/python2.7/dist-packages/gphoto2/file.py", line 89, in import gphoto2.filesys File "/usr/local/lib/python2.7/dist-packages/gphoto2/filesys.py", line 90, in import gphoto2.list File "/usr/local/lib/python2.7/dist-packages/gphoto2/list.py", line 91, in import gphoto2.port_info_list File "/usr/local/lib/python2.7/dist-packages/gphoto2/port_info_list.py", line 92, in import gphoto2.port_log File "/usr/local/lib/python2.7/dist-packages/gphoto2/port_log.py", line 93, in import gphoto2.result File "/usr/local/lib/python2.7/dist-packages/gphoto2/result.py", line 100, in GP_ERROR_CANCEL : logging.INFO, NameError: name 'GP_ERROR_CANCEL' is not defined

jim-easterbrook commented 6 years ago

Which version of libgphoto2 do you have? Which version of python-gphoto2? How did you install python-gphoto2?

BeebBenjamin commented 6 years ago

libgphoto2-2.5.16

Installed it using git + SWIG.

jim-easterbrook commented 6 years ago

Ah, I didn't expect that. Which SWIG version?

jim-easterbrook commented 6 years ago

To my surprise I've managed to reproduce this bug - it's caused by not using the SWIG -builtin flag so I guess you're still on SWIG 2.0.11.

jim-easterbrook commented 6 years ago

This bug was introduced in commit 24b861a, so only affects release v1.8.1. Temporary solution is to install v1.8.0, or install using pip so you get code built with the -builtin flag (which is generally a lot better anyway).

BeebBenjamin commented 6 years ago

OK. I started from scratch and installed via pip. Now I get this error:

File "libgphoto_example.py", line 1, in import gphoto2 as gp File "/usr/local/lib/python2.7/dist-packages/gphoto2/init.py", line 17, in from gphoto2.abilities_list import * File "/usr/local/lib/python2.7/dist-packages/gphoto2/abilities_list.py", line 9, in import gphoto2.camera File "/usr/local/lib/python2.7/dist-packages/gphoto2/camera.py", line 10, in import gphoto2.context File "/usr/local/lib/python2.7/dist-packages/gphoto2/context.py", line 11, in import gphoto2.file File "/usr/local/lib/python2.7/dist-packages/gphoto2/file.py", line 12, in import gphoto2.filesys File "/usr/local/lib/python2.7/dist-packages/gphoto2/filesys.py", line 13, in import gphoto2.list File "/usr/local/lib/python2.7/dist-packages/gphoto2/list.py", line 14, in import gphoto2.port_info_list File "/usr/local/lib/python2.7/dist-packages/gphoto2/port_info_list.py", line 15, in import gphoto2.port_log File "/usr/local/lib/python2.7/dist-packages/gphoto2/port_log.py", line 16, in import gphoto2.result File "/usr/local/lib/python2.7/dist-packages/gphoto2/result.py", line 17, in import gphoto2.version File "/usr/local/lib/python2.7/dist-packages/gphoto2/version.py", line 31, in _version = swig_import_helper() File "/usr/local/lib/python2.7/dist-packages/gphoto2/version.py", line 30, in swig_import_helper return importlib.import_module('_version') File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) ImportError: No module named _version

jim-easterbrook commented 6 years ago

This looks like the installer either didn't run properly or you're picking up remnants of a previous installation. (I think this can happen because the Python parts of the python-gphoto2 package have older dates in the pip download than the ones you made when you installed from git.) Try sudo rm -rf /usr/local/lib/python2.7/dist-packages/gphoto2* to wipe all previous installations before installing again.

BeebBenjamin commented 6 years ago

OK. I get the same error. I am using python 2.7.6 if this makes a difference.

jim-easterbrook commented 6 years ago

What's the output of ls -l /usr/local/lib/python2.7/dist-packages/gphoto2/?

BeebBenjamin commented 6 years ago
total 3628
-rw-r--r-- 1 root staff   3683 Jan  2 17:35 abilities_list.py
-rw-r--r-- 1 root staff   4129 Jan  2 17:35 abilities_list.pyc
-rwxr-xr-x 1 root staff 368600 Jan  2 17:35 _abilities_list.so
-rw-r--r-- 1 root staff   3580 Jan  2 17:35 camera.py
-rw-r--r-- 1 root staff   4057 Jan  2 17:35 camera.pyc
-rwxr-xr-x 1 root staff 578940 Jan  2 17:35 _camera.so
-rw-r--r-- 1 root staff   3591 Jan  2 17:35 context.py
-rw-r--r-- 1 root staff   4066 Jan  2 17:35 context.pyc
-rwxr-xr-x 1 root staff 262902 Jan  2 17:35 _context.so
-rw-r--r-- 1 root staff   3552 Jan  2 17:35 file.py
-rw-r--r-- 1 root staff   4039 Jan  2 17:35 file.pyc
-rwxr-xr-x 1 root staff 346463 Jan  2 17:35 _file.so
-rw-r--r-- 1 root staff   3597 Jan  2 17:35 filesys.py
-rw-r--r-- 1 root staff   4066 Jan  2 17:35 filesys.pyc
-rwxr-xr-x 1 root staff 509335 Jan  2 17:35 _filesys.so
-rw-r--r-- 1 root staff    750 Jan  2 17:35 __init__.py
-rw-r--r-- 1 root staff   1230 Jan  2 17:35 __init__.pyc
-rw-r--r-- 1 root staff   3552 Jan  2 17:35 list.py
-rw-r--r-- 1 root staff   4039 Jan  2 17:35 list.pyc
-rwxr-xr-x 1 root staff 276840 Jan  2 17:35 _list.so
-rw-r--r-- 1 root staff   3683 Jan  2 17:35 port_info_list.py
-rw-r--r-- 1 root staff   4129 Jan  2 17:35 port_info_list.pyc
-rwxr-xr-x 1 root staff 276241 Jan  2 17:35 _port_info_list.so
-rw-r--r-- 1 root staff   4706 Jan  2 17:35 port_log.py
-rw-r--r-- 1 root staff   5282 Jan  2 17:35 port_log.pyc
-rwxr-xr-x 1 root staff 162291 Jan  2 17:35 _port_log.so
-rw-r--r-- 1 root staff   4810 Jan  2 17:35 result.py
-rw-r--r-- 1 root staff   5296 Jan  2 17:35 result.pyc
-rwxr-xr-x 1 root staff 180092 Jan  2 17:35 _result.so
-rw-r--r-- 1 root staff   3590 Jan  2 17:35 version.py
-rw-r--r-- 1 root staff   4066 Jan  2 17:35 version.pyc
-rwxr-xr-x 1 root staff 132604 Jan  2 17:35 _version.so
-rw-r--r-- 1 root staff   3580 Jan  2 17:35 widget.py
-rw-r--r-- 1 root staff   4057 Jan  2 17:35 widget.pyc
-rwxr-xr-x 1 root staff 476221 Jan  2 17:35 _widget.so
jim-easterbrook commented 6 years ago

That looks OK - the .so compiled modules are there, so should be being found. Can you run ldd on one of the .so files to see if any required libraries are missing?

BeebBenjamin commented 6 years ago
linux-vdso.so.1 =>  (0x00007fffb0d16000)
libgphoto2.so.6 => /usr/lib/x86_64-linux-gnu/libgphoto2.so.6 (0x00007f38c3cfd000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f38c3adf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f38c3715000)
libgphoto2_port.so.10 => /usr/lib/x86_64-linux-gnu/libgphoto2_port.so.10 (0x00007f38c350b000)
libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f38c3301000)
libexif.so.12 => /usr/lib/x86_64-linux-gnu/libexif.so.12 (0x00007f38c30bc000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f38c2db6000)
/lib64/ld-linux-x86-64.so.2 (0x000055e7d3cd9000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f38c2bb2000)
jim-easterbrook commented 6 years ago

So no problem there then. I'm running out of ideas now. Perhaps try the previous version:

sudo pip uninstall gphoto2
sudo pip install gphoto2==1.8.0
BeebBenjamin commented 6 years ago

Looks like it installed ok. But using one of your examples, I get this issue now.

WARNING: gphoto2: (gp_port_serial_close [unix.c:465]) Invalid parameters: 'path' is NULL/FALSE. WARNING: gphoto2: (gp_context_error) Could not detect any camera Traceback (most recent call last): File "libgphoto_example.py", line 49, in sys.exit(main()) File "libgphoto_example.py", line 34, in main gp.check_result(gp.gp_camera_init(camera)) File "/usr/local/lib/python2.7/dist-packages/gphoto2/result.py", line 165, in check_result raise GPhoto2Error(error) gphoto2.GPhoto2Error: [-105] Unknown model

If I use python to talk to gphoto2 using subprocess and the same camera, I get no such errors and I can access the camera.

jim-easterbrook commented 6 years ago

gphoto2.GPhoto2Error: [-105] Unknown model is the usual response when there's no camera plugged in (or switched on). The first warning message is typical libgphoto2 verbosity, not really an error. The second is also saying there's no camera. PS I'm very sorry about the difficulty you had installing. There's definitely a problem with v1.8.1 which hadn't showed up in my testing, but which I'm sure is fixed in 24b861a. It may not have shown up in my tests because of initialisation order being indeterminate, but I don't really know.

BeebBenjamin commented 6 years ago

Thanks for your help anyway. Looks like I will have to skip using python-gphoto altogether, gphoto2 detects my camera no problems. I don't know why none of the examples provided with this module detects any of my cameras.

jim-easterbrook commented 6 years ago

That's very strange. gphoto2 is using the exact same library so I'm surprised the examples are failing.

BeebBenjamin commented 6 years ago

The one thing in common is:

WARNING: gphoto2: (gp_port_serial_close [unix.c:465]) Invalid parameters: 'path' is NULL/FALSE.

jim-easterbrook commented 6 years ago

There was something similar in #18 which was never resolved (as far as I know). I assume you're running gphoto2 as the same user so it shouldn't be a permissions problem. Other things to check are that gvfs or similar isn't taking ownership of the usb port, but I'd expect that to upset gphoto2 as well. (You could also run ldd on the gphoto2 executable to check it really is using the same library, but I doubt this is the problem.)

jim-easterbrook commented 6 years ago

PS Is your camera visible to the list-cameras.py example? If so, can you select it with the choose-camera.py example?

BeebBenjamin commented 6 years ago

There is a difference in the outputs, mostly use the same .so but there is one difference:

gphoto2 uses:

libgphoto2_port.so.10 => /usr/lib/x86_64-linux-gnu/libgphoto2_port.so.10 (0x00007fb50a2df000)

python-gphoto2 uses:

libgphoto2_port.so.12 => /usr/local/lib/libgphoto2_port.so.12 (0x00007f7ee70b5000)

BeebBenjamin commented 6 years ago

It is the list-cameras.py example I am using!

jim-easterbrook commented 6 years ago

That looks as if gphoto2 was installed by your package manager (the library is in /usr/lib/x86_64-linux-gnu) whereas python-gphoto2 is picking up a version in /usr/local/lib. Can you try removing any gphoto2 related stuff from /usr/local/lib and then do a new gphoto2 install (with pip - it should pick up the new v1.8.2) so it uses the package manager's libgphoto2.

BeebBenjamin commented 6 years ago

OK removed everything. Re-compiled libghoto2 from github and reinstalled python-gphoto2 using pip. Use list-cameras.py, same error.

WARNING: gphoto2: (gp_port_serial_close [unix.c:465]) Invalid parameters: 'path' is NULL/FALSE.

jim-easterbrook commented 6 years ago

I'm not convinced that warning (see source here https://github.com/gphoto/libgphoto2/blob/master/libgphoto2_port/serial/unix.c#L443) has any bearing on the failure to detect your camera - I suspect you'd see it from the gphoto2 programme if you turn on verbose debugging. You say you compiled libghoto2 from github - why? It would be easier to get python-gphoto2 working with the system libgphoto2 before you start rolling your own.

BeebBenjamin commented 6 years ago

OK. So the problem turns out to be an out of date system libgphoto2!

I once again removed everything, then used the updater script which is floating around (the one which doesn't remove ubuntu-desktop and wine), and it works as expected.

The issue is the fact that with Ubuntu 14.10 LTS if you use the apt-get to install libgphoto2-dev it is dependant upon libgphoto2_port.so.10

It is now using:

gphoto2 2.5.15 gcc, popt(m), exif, no cdk, no aa, jpeg, no readline libgphoto2 2.5.15 all camlibs, gcc, ltdl, EXIF libgphoto2_port 0.12.0 iolibs: disk ptpip serial usb usbdiskdirect usbscsi, gcc, ltdl, USB, serial without locking

jim-easterbrook commented 6 years ago

Just to confirm - you've got gphoto2 and python-gphoto2 using the same libs (as reported by ldd) and both able to detect your cameras?

BeebBenjamin commented 6 years ago

Yes, that is correct! Problem solved.