PyUSB provides easy USB access for Python, abstracting away the low-level details of USB communication. It allows Python applications to interact with USB devices on various operating systems. The current version is 1.3.1, and it receives updates to fix bugs and maintain compatibility, though releases are not on a fixed schedule.
pip install pyusbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to find an attached USB device, retrieve its manufacturer and product strings, and properly dispose of resources. Replace `dev = usb.core.find()` with specific `idVendor` and `idProduct` for a targeted search.
Install `libusb-1.0` on your operating system. For example: - Debian/Ubuntu: `sudo apt-get install libusb-1.0-0-dev` - macOS (Homebrew): `brew install libusb` - Windows: Download binaries from the libusb website and ensure they are in your system's PATH or explicitly specified using `usb.backend.libusb1.get_backend()`.
Run your Python script as root (`sudo python your_script.py`) or, for a more secure approach, create a udev rule (e.g., `/etc/udev/rules.d/99-mydevice.rules`) that grants access to specific devices and add your user to the relevant group. Example rule: `SUBSYSTEM=="usb", ATTR{idVendor}=="<vendor_id>", ATTR{idProduct}=="<product_id>", MODE="0666", GROUP="plugdev"`.Upgrade your Python environment to version 3.9 or newer. If you must use an older Python version, restrict your PyUSB dependency to `<1.3.0` (e.g., `pip install 'pyusb<1.3.0'`).
Upgrade to PyUSB 1.3.1 or newer to ensure `ctrl_transfer` correctly utilizes supplied read buffers. If stuck on 1.3.0, avoid pre-allocating read buffers for `ctrl_transfer` and rely on the function to return a newly allocated buffer.
If you rely on `Device` objects being hashable (e.g., storing them in sets or using them as dict keys), ensure you are on PyUSB 1.2.1 or newer. Be aware of the `__eq__` implementation changes when comparing device objects between 1.1.x and 1.2.x+.
Install `libusb` on your operating system (e.g., `sudo apt install libusb-1.0-0-dev` on Linux, or use Zadig on Windows), and ensure its path is discoverable, or explicitly specify its location using `usb.backend.libusb1.get_backend(find_library=lambda x: "/path/to/libusb-1.0.so")`.
On Linux, create a udev rule for the device (e.g., `SUBSYSTEM=="usb", ATTR{idVendor}=="VVVV", ATTR{idProduct}=="PPPP", MODE="0666"`) and reload udev rules, or temporarily run your script with `sudo` (not recommended for production).Install `libusb` on Windows (e.g., using Zadig or MSYS2/MinGW), then ensure `libusb-1.0.dll` is in a directory listed in your system's PATH environment variable, or manually specify its path: `backend = usb.backend.libusb1.get_backend(find_library=lambda x: r'C:\Path\To\libusb-1.0.dll')`.
Ensure all other applications that might be using the device are closed, or on Linux, explicitly detach the kernel driver using `dev.detach_kernel_driver(interface_number)` before claiming the interface.
No dependency data recorded yet.