apmorton / pyhidapi

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

Add MacOS hidapi shared object to library_path #17

Closed JnyJny closed 5 years ago

JnyJny commented 6 years ago

MacOS 10.13.6 Python 3.7.0

After installing Signal 11 hidapi (via brew), adding 'libhidapi.dyn' to library_paths allows pyhidapi to successfully find the shared object.

This should solve the issue discussed in the README with regard to compiling the shared object by hand.

JnyJny commented 6 years ago

It works :)

Python 3.7.0 (default, Jun 28 2018, 07:39:16) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda custom (64-bit) on darwin
Type "help", "copyright", "credits" or "license" for more information.
Executed  ~/.pythonrc, interactive experience now turbo-charged.
> import hid
> hid.enumerate()
[{'path': b'USB_05ac_0262_14400000', 'vendor_id': 1452, 'product_id': 610, 'serial_number': '', 'release_number': 549, 'manufacturer_string': 'Apple Inc.', 'product_string': 'Apple Internal Keyboard / Trackpad', 'usage_page': 65280, 'usage': 1, 'interface_number': -1}, {'path': b'USB_05ac_0262_14400000', 'vendor_id': 1452, 'product_id': 610, 'serial_number': '', 'release_number': 549, 'manufacturer_string': 'Apple Inc.', 'product_string': 'Apple Internal Keyboard / Trackpad', 'usage_page': 1, 'usage': 2, 'interface_number': -1}, {'path': b'USB_05ac_0262_14400000', 'vendor_id': 1452, 'product_id': 610, 'serial_number': '', 'release_number': 549, 'manufacturer_string': 'Apple Inc.', 'product_string': 'Apple Internal Keyboard / Trackpad', 'usage_page': 1, 'usage': 6, 'interface_number': -1}]
apmorton commented 5 years ago

If you could resolve the merge conflict with master I will happily merge this

JnyJny commented 5 years ago

Thanks @apmorton.

Qbicz commented 5 years ago

I believe removing hidapi.dll stops it from finding the library on Windows.

apmorton commented 5 years ago

Ah shit, didn't notice. It was not present in the original PR, and the rebase against master was botched.

Thanks for the heads up - fixed on master.

Qbicz commented 5 years ago

Thanks @apmorton. What do you think about providing DLL files with the repo? I'm going to provide 32-bit and 64-bit MSVC DLLs in my fork and make them copy to some directory on PATH. Would you accept such pull request? This would greatly help Windows users with setup.

See e.g. https://github.com/Qbicz/pyhidapi/commit/e330ead2266c1dee861f7f2f9052ae91c9c66f67

apmorton commented 5 years ago

Long story short, I am not prepared to distribute binaries that I didn't personally produce. I am happy to accept a PR updating the readme to point users to your fork for better windows support if you get there.

Long story long, I built this library primarily with nix in mind, where the hidapi library was already available as a binary component in distro repos. Prior to this library the only python bindings available for hidapi required compiling a binary component (either cython based or a standard cpython based binary module). Back then binary module distribution through pip/etc was not really common, so getting anything working was a nightmare.

In all honesty, for windows users, https://pypi.org/project/hidapi/ is probably a better choice nowadays - since it provides statically linked binary builds directly from pypi. For Mac and nix users, it is only distributed as a source package, but those platforms tend to have a working compiler setup more readily available.