leapc-python-bindings icon indicating copy to clipboard operation
leapc-python-bindings copied to clipboard

Error running sample project

Open The-Real-Thisas opened this issue 1 year ago • 12 comments

Traceback (most recent call last):
  File "/Users/thisas/Desktop/leapc-python-bindings/leapc-python-api/src/leap/__init__.py", line 74, in <module>
    from leapc_cffi import ffi, libleapc
  File "/Applications/Ultraleap Hand Tracking.app/Contents/LeapSDK/leapc_cffi/__init__.py", line 1, in <module>
    from ._leapc_cffi import ffi, lib as libleapc
ModuleNotFoundError: No module named 'leapc_cffi._leapc_cffi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/thisas/Desktop/leapc-python-bindings/examples/tracking_event_example.py", line 7, in <module>
    import leap
  File "/Users/thisas/Desktop/leapc-python-bindings/leapc-python-api/src/leap/__init__.py", line 80, in <module>
    raise ImportError(
ImportError: Cannot import leapc_cffi: Unknown error, please consult readme for help. Attempting to find leapc_cffi within /Applications/Ultraleap Hand Tracking.app/Contents/LeapSDK. Caught ImportError: No module named 'leapc_cffi._leapc_cffi'

The-Real-Thisas avatar Dec 23 '23 09:12 The-Real-Thisas

same

jeffp123 avatar Dec 24 '23 06:12 jeffp123

Renaming ~\Ultraleap\LeapSDK\leapc_cffi\_leapc_cffi.cp38-win_amd64.pyd or whatever .pyd/.so is present to _leapc_cffi.pyd/_leapc_cffi.so seemed to fix the issue for me.

EthoIRL avatar Dec 26 '23 05:12 EthoIRL

@EthoIRL I've tried that, Screenshot 2023-12-26 at 3 16 10 pm But it still seems to give the same error

(base)  ~/Desktop/leapc-python-bindings/ [main] python3 examples/visualiser.py
Traceback (most recent call last):
  File "/Users/thisas/Desktop/leapc-python-bindings/leapc-python-api/src/leap/__init__.py", line 74, in <module>
    from leapc_cffi import ffi, libleapc
  File "/Applications/Ultraleap Hand Tracking.app/Contents/LeapSDK/leapc_cffi/__init__.py", line 1, in <module>
    from ._leapc_cffi import ffi, lib as libleapc
ModuleNotFoundError: No module named 'leapc_cffi._leapc_cffi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/thisas/Desktop/leapc-python-bindings/examples/visualiser.py", line 1, in <module>
    import leap
  File "/Users/thisas/Desktop/leapc-python-bindings/leapc-python-api/src/leap/__init__.py", line 80, in <module>
    raise ImportError(
ImportError: Cannot import leapc_cffi: Unknown error, please consult readme for help. Attempting to find leapc_cffi within /Applications/Ultraleap Hand Tracking.app/Contents/LeapSDK. Caught ImportError: No module named 'leapc_cffi._leapc_cffi'

The-Real-Thisas avatar Dec 26 '23 12:12 The-Real-Thisas

@The-Real-Thisas _leapc_cffi*.pyd is specifically for window's and window's alone. Try renaming _leapc_cffi.cpython-38-darwin.so to _leapc_cffi.so. I've only tested this on a window's machine so your mileage may vary.

https://github.com/ultraleap/leapc-python-bindings/blob/2341c6c3db5dc08236bb52890d8c43a224139694/leapc-python-api/src/leap/init.py#L24C1-L29C2

EthoIRL avatar Dec 26 '23 19:12 EthoIRL

Have you tried rebuilding the module? https://github.com/ultraleap/leapc-python-bindings#missing-compiled-module

rodolpheh avatar Dec 27 '23 10:12 rodolpheh

Also on MacOS. I tried renaming that _leapc_cffi.cpython-38-darwin.so to _leapc_cffi.so and re-ran:

python -m build leapc-cffi
pip install leapc-cffi/dist/leapc_cffi-0.0.1.tar.gz
pip install -e leapc-python-api
python examples/tracking_event_example.py

and still getting:

ImportError: Cannot import leapc_cffi: Unknown error, please consult readme for help. Attempting to find leapc_cffi within /Applications/Ultraleap Hand Tracking.app/Contents/LeapSDK. Caught ImportError: dlopen(/Users/chaim/miniconda3/lib/python3.9/site-packages/leapc_cffi/_leapc_cffi.abi3.so, 0x0002): symbol not found in flat namespace '_LeapCameraMatrix'

when I try the example.


I remember a few years ago, there was a Javascript API and all that was necessary was to plug in the Leap Motion device and you could start getting signal from it to do cool things in a web browser. I actually wanted to make a demo to show "how easy it is" to get started with the Leap Motion for an upcoming presentation, but with the latest updates it looks like you are out of luck unless you are using Unity or Unreal Engine.

This Python API seemed promising, but that it cannot even run the example in the README is disappointing.


I still have yet to try this on a Raspberry Pi 4. (I tried it on a RP3 and it did not work, but that seems correct according to the system requirements.) Still though, the barriers to entry with the Leap Motion seem to have been raised in the past few years.

jeffp123 avatar Dec 27 '23 16:12 jeffp123

Oh, re-reading, I just noticed the error message above is not the same as what I am getting:

symbol not found in flat namespace '_LeapCameraMatrix'

If it would help, I could make a new issue for this...

jeffp123 avatar Dec 27 '23 16:12 jeffp123

It seems to work @EthoIRL after renaming to _leapc_cffi.so , trying to find the root of this bug it seems to be in https://github.com/ultraleap/leapc-python-bindings/blob/main/leapc-cffi/setup.py because in https://github.com/ultraleap/leapc-python-bindings/blob/main/leapc-python-api/src/leap/init.py#L24 the check passes however. Here https://github.com/ultraleap/leapc-python-bindings/blob/main/leapc-cffi/setup.py#L36 it's static. Whats weird is that on Darwin (mac) it's looking for 'libLeapC.5.dylib' which does indeed exist so I don't know what the libLeapC.so has to do with it, it's possible since I'm on m1 it's trying to compile rather for Linux-Arm ?

The-Real-Thisas avatar Dec 30 '23 17:12 The-Real-Thisas

I'm going to see if I can make a fix by using fnmatch to find the file using the same patterns as the https://github.com/ultraleap/leapc-python-bindings/blob/main/leapc-python-api/src/leap/init.py#L24

The-Real-Thisas avatar Dec 30 '23 17:12 The-Real-Thisas

I don't quite understand why in https://github.com/ultraleap/leapc-python-bindings/blob/main/leapc-python-api/src/leap/init.py#L17 references the dylib https://github.com/ultraleap/leapc-python-bindings/blob/main/leapc-python-api/src/leap/init.py#L24C1-L24C1 references the .so file ?

The-Real-Thisas avatar Dec 30 '23 17:12 The-Real-Thisas

@chaimpeck This error happens if you installed the wrong version of the hand tracking on your Mac. There are two versions depending on your architecture: M1 & M2 (for ARM64), and Intel (for x64). Make sure you use the right one for your Mac.

@The-Real-Thisas If Python cannot find the library it could be because you're using a different version of the Python interpreter than the one that was used to build the CFFI module (CPython 3.8 at the time of writing this). In that case, you need to rebuild the module: https://github.com/ultraleap/leapc-python-bindings#missing-compiled-module

I've been testing this on a Mac M2 today and it works. No need to rename anything, just following the instructions should work.

RodolpheHoudas-UL avatar Apr 09 '24 10:04 RodolpheHoudas-UL

@chaimpeck This error happens if you installed the wrong version of the hand tracking on your Mac. There are two versions depending on your architecture: M1 & M2 (for ARM64), and Intel (for x64). Make sure you use the right one for your Mac.

I have the right version installed and got the same error, tried it today on a M1 Mac, with Python 3.8 (even got the error after rebuilding the CFFI module).

ericelbing avatar Apr 10 '24 16:04 ericelbing