pupil-labs / apriltags

Python bindings for the apriltags3 library
https://pupil-apriltags.readthedocs.io/en/latest/index.html
Other
107 stars 29 forks source link

DLL loading process not locating pthreads #53

Open kyflores opened 2 years ago

kyflores commented 2 years ago

Hi,

I'm on Windows 11 10.0.22621 with Python 3.9.13 and using pupil-apriltags 1.0.4.post8, installed with pip in an anaconda environment.

When instantiating the detector, I get: FileNotFoundError: Could not find module 'C:\Python39\lib\site-packages\pupil_apriltags\lib\apriltag.dll' (or one of its dependencies). Try using the full path with constructor syntax.

On my system, the problem seems to be with the pthreadVC2.dll:

$ ldd lib/apriltag.dll
        ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7fff79c30000)
        KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7fff78280000)
        KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7fff77090000)
        msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7fff78d30000)
        apriltag.dll => /c/Users/myuser/anaconda3/envs/cv/Lib/site-packages/pupil_apriltags/lib/apriltag.dll (0x7ffee6f20000)
        ucrtbase.dll => /c/Windows/System32/ucrtbase.dll (0x7fff778a0000)
        vcruntime140.dll => /c/Windows/System32/vcruntime140.dll (0x7fff621a0000)
        winmm.dll => /c/Windows/System32/winmm.dll (0x7fff72890000)
        pthreadVC2.dll => not found

I installed the pupil-pthreads-win package first, and that didn't solve the problem. I then removed the check for < v3.8 at L315.

After this change the library works. I have no experience w/ how this process is supposed to work on Windows, but maybe this will help identify a problem?

Mhdfk commented 1 year ago

how did you remove the check?

kyflores commented 1 year ago

how did you remove the check?

I had this ugly hack in my jupyter notebook, YMMV. In short it locates bindings.py in your interpreter's package path and then edits that line.

!pip install pupil-apriltags==1.0.4.post8
import pupil_apriltags as atgs
import os
if os.name == 'nt':
    !pip install pupil-pthreads-win
    init_path = atgs.__file__
    at_dir = os.path.dirname(init_path)
    target = at_dir + '\\bindings.py'
    lines = None
    with open(target, 'r', encoding='utf-8') as file:
        lines = file.readlines()
        lines[314] = "        if platform.system() == \"Windows\":\n"

    with open(target, 'w', encoding='utf-8') as file:
        file.writelines(lines)

    from importlib import reload
    reload(atgs)
else:
    print("Not on windows. Skipping patch.")
Mhdfk commented 1 year ago

I ended up doing a fresh install for the package and adding this line before the detector os.add_dll_directory("C:/Users/mff5/anaconda3/Lib/site-packages/pupil_apriltags.libs")

It worked but but thank you for replying so fast!!