apmorton / pyhidapi

hidapi bindings in ctypes
MIT License
111 stars 42 forks source link

added path for hidapi.dll for windows #56

Open rundekugel opened 1 year ago

rundekugel commented 1 year ago

I love this lib, but when I distributed my python-usb-hid script, some users can't execute it.

This added paths helped, if the pyhidapi is not installed, but a copy is distributed with the script, and the dll is also only copied in to the folder of script or lib.

apmorton commented 1 year ago

I would recommend changing the path environment variable to include the absolute path to where you distribute the dll as part of your script before importing the hid library.

I'm a bit hesitant to add relative paths here since that could pose a security risk in a lot of contexts.

ndreys commented 7 months ago

@rundekugel if you are distributing pyhidapi, you can probably place the .dll next to it and it should work, see https://bugs.python.org/issue43173 However, if I remember correctly, I wasn't able to make this work when using Python installed via MS Store, so there I also had to do:

if sys.platform == 'win32':
    os.add_dll_directory(os.path.dirname(os.path.abspath(__file__)))

all that is to say, I think you can solve your problem without making any changes to this lib.