2025, Oct 29 19:00

hidapi installed but cannot import in Python 3.12 on Windows 11: the fix is to import hid

Installed hidapi but hit ModuleNotFoundError on Windows 11? Import hid, not hidapi, and install through the same interpreter using python -m pip reliably.

When a package installs cleanly but importing it explodes with ModuleNotFoundError, it usually feels like the ground shifted under the tooling. Here’s a concise walkthrough of a real-world case on Windows 11 with Python 3.12.6: installing hidapi via pip succeeded, yet import hidapi failed at runtime. The fix turned out to be about the import name, not the installation.

Problem: installed, but cannot import

The application aims to locate a specific USB HID device by vendor_id and product_id and then read a payload. The code below shows the intended flow and triggers the error during import.

import hidapi
# search for the target HID device
all_nodes = hidapi.DeviceManager().devices()
for node in all_nodes:
    if node.vendor_id == 0x2341 and node.product_id == 0x0042:
        pad_handle = node
        break
# read and print 64 bytes
payload = pad_handle.read(64)
print(payload)

The installation looks fine, but the interpreter cannot find the module:

pip3 install hidapi
Successfully installed hidapi-0.14.0.post4
python -u "C:\Users\...\HID_test.py"
Traceback (most recent call last):
  File "C:\Users\...\HID_test.py", line 1, in <module>
    import hidapi
ModuleNotFoundError: No module named 'hidapi'

What’s actually happening

The import name exposed by the installed package is hid, not hidapi. The project example demonstrates using import hid, which aligns with the working API surface. You can see this pattern in the project’s example: https://github.com/trezor/cython-hidapi/blob/master/try.py. Documentation is available here: https://github.com/trezor/cython-hidapi/blob/master/docs/.

Solution: import the correct module name

Switch the import to hid and keep the program flow unchanged. The logic still enumerates devices, matches on vendor_id and product_id, reads 64 bytes, and prints the buffer.

import hid
dev_catalog = hid.DeviceManager().devices()
for item in dev_catalog:
    if item.vendor_id == 0x2341 and item.product_id == 0x0042:
        controller = item
        break
chunk = controller.read(64)
print(chunk)

If the import still fails after this change, ensure the package is installed into the exact interpreter you use to run the script. One reliable way is to drive pip through the interpreter explicitly and then execute the code with the same interpreter:

python -m pip install hidapi
python -u "C:\path\to\HID_test.py"

Why this matters

Package names and importable module names don’t always match. In day-to-day Python work, that discrepancy is easy to overlook, especially when switching between libraries with similar names or bindings. Recognizing this pattern helps you avoid chasing phantom environment issues and shortens the time from install to working code. It’s also a reminder to align the pip target interpreter with the runtime interpreter, which prevents subtle “works in one shell, fails in another” scenarios.

Takeaways

If you install hidapi on Windows 11 with Python 3.12.6 and hit ModuleNotFoundError when importing hidapi, switch the import to hid. If issues persist, install via python -m pip and launch the script with the same python. When in doubt, check the project’s examples and docs to confirm the intended import path and API surface. Small naming differences like this are common, and catching them early saves a lot of time.

The article is based on a question from StackOverflow by Akut Luna and an answer by DeNiks_One.