Libusb Python Package (Installer)
libusb-package is a Python library that functions primarily as an installation vehicle for the libusb shared C libraries, making it easier to install tools and applications that require libusb, such as pyusb. It bundles the necessary libusb binaries for various platforms and architectures, simplifying deployment by avoiding manual libusb installation. The package is actively maintained, with version 1.0.26.3 being the latest, and receives updates to support new Python versions and upstream libusb releases.
Warnings
- breaking Python 3.6 support was officially dropped starting with `libusb-package` v1.0.26.1.
- gotcha On Windows, `libusb-package` installs the `libusb` DLL, but it *does not* install the necessary device drivers (e.g., WinUSB or libusbK). Users must manually install these drivers for their specific USB devices, often using tools like Zadig. Without the correct driver, your Python application will not be able to access the USB device.
- gotcha If `libusb-package` is installed from a source distribution and the underlying C `libusb` build fails (e.g., due to missing build tools), the Python package installation will still succeed but will result in an 'empty' `libusb-package` that does not contain the shared library. In such cases, `libusb_package.get_library_path()` will return `None`, and `find_library()` will fall back to `ctypes.util.find_library()` to search for a system-wide `libusb` installation.
- gotcha Versions of `libusb-package` prior to 1.0.24.1 had an issue with the `functools.lru_cache()` decorator that prevented it from working correctly on Python versions earlier than 3.9.
- deprecated The internal usage of `importlib.resources` API was replaced in v1.0.26.2 due to deprecation. While this was an internal change, direct interaction with `libusb_package`'s resource loading mechanisms (if any existed in user code) might require review.
Install
-
pip install libusb-package
Imports
- libusb_package
import libusb_package
Quickstart
import libusb_package
import usb.core
import usb.backend.libusb1
# Get a PyUSB backend using the bundled libusb library
backend = usb.backend.libusb1.get_backend(find_library=libusb_package.find_library)
# Use the backend to find USB devices (example with pyusb)
dev = usb.core.find(idVendor=0xffff, idProduct=0xffff, backend=backend)
if dev is None:
print("Device not found. Make sure it's connected and drivers are installed (especially on Windows).")
else:
print(f"Found device: {dev.product} (Bus {dev.bus}, Address {dev.address})")
# Further operations with 'dev' using pyusb