gphoto / libgphoto2

The libgphoto2 camera access and control library.
GNU Lesser General Public License v2.1
989 stars 316 forks source link

Advice needed: portable pure-Python solution for my camera? #973

Closed FilipDominec closed 1 month ago

FilipDominec commented 2 months ago

In our optical laboratory, I use an old Canon 350D to take tethered photos, as a part of an experiment that is controlled by a Python script.

It already works great on Linux, but now we need to run the script also on Windows 10. And then it goes complicated. While there are reports (https://github.com/gphoto/libgphoto2/issues/279) on libgphoto2 already being built on Windows, we found no easy way to give it a try.

Therefore I would be very thankful to all developers or experienced users for an advice:

  1. Is it easier to somehow install / compile libgphoto2 so that my script can import gphoto2 on Windows,
  2. or should I take a deeper look into the C sources, at camlibs/canon.c and try building a cross-platform module that communicates with my specific camera using pyUSB backend? (Actually at least one similar project exists: https://pypi.org/project/canon-remote/)
  3. If so, would anybody be interested in using the existing C codebase to generate a cross-platform, pure Python+pyUSB solution for all supported cameras? It would certainly present quite a lot of work, but many people could profit from that.
  4. Or is there some better option yet?

I also suggest the documentation could clarify the topic of "libgphoto and Windows" for other users - apparently I am not the first one solving this problem. Thanks a lot!

msmeissn commented 2 months ago

The python bindings provide wheels with pre-built binaries, but I am not sure if they are built for windows.

@jim-easterbrook ?

jim-easterbrook commented 2 months ago

Sorry for the delayed reply, I've been away for a few days.

No, I don't provide pre-built binaries for Windows. As I understand it, libgphoto2 can only be built on Windows using MSYS2/MinGW. My only Windows installation is Windows 7 and MSYS2 is no longer supported.

Things are further complicated by building for "native" MSYS2 or trying to create a Python binary compatible with the standard Windows Python (which uses the MSVC compiler suite). I'm not sufficiently expert at Windows or MSYS2 to know how best to do this, and I don't have a test environment to do it in.

MSYS2 provide several builds of libgphoto2: https://packages.msys2.org/search?t=binpkg&q=gphoto2 The base package https://packages.msys2.org/base/mingw-w64-libgphoto2 should be usable with python-gphoto2 if you do a non-binary install. This compiles the python-gphoto2 interface to link with the "system" installed libgphoto2. It's a long time since I tried this though.

FilipDominec commented 2 months ago

Thank you both for your comments.

If you personally needed to run one particular type of camera from Windows, would you consider sniffing the Linux-libgphoto-camera communication and rewriting the data rx/tx using libusb? Do you think there is some serious reason not to try it?

msmeissn commented 2 months ago

you would need to reimplement parts of libgphoto2. so it would make more sense to try building libgphoto2 itself and python bindings with MSYS2 or so

FilipDominec commented 1 month ago

Thank you for your responses, one day we might try recompiling for Windows.

So far we are 99% happy with running python-gphoto under Ubuntu in VMware.

alexisdrakopoulos commented 1 month ago

@FilipDominec why not try WSL instead of VMWare?

FilipDominec commented 2 weeks ago

We are somewhat busy and have not experience with WSL, but we will give it a try one day. Thanks.