On Python 3.14, importing usb1 raises a DeprecationWarning that is treated as an error, preventing the module from loading.
Environment:
- Python 3.14.3
- python-libusb1 (latest from PyPI)
- Ubuntu 24.04.3 LTS
Traceback
usb1/__init__.py:61: in <module>
from . import _libusb1 as libusb1
usb1/_libusb1.py:1071: in <module>
class libusb_control_setup(Structure):
ctypes/_layout.py:81: in get_layout
warnings._deprecated(
E DeprecationWarning: Due to '_pack_', the 'libusb_control_setup' Structure will use memory layout
compatible with MSVC (Windows). If this is intended, set _layout_ to 'ms'. The implicit default
is deprecated and slated to become an error in Python 3.19.
Root cause:
Python 3.14 (changelog (https://docs.python.org/3.14/whatsnew/3.14.html)) deprecated the implicit behavior of _pack_ in ctypes.Structure without an explicit _layout_ attribute. The libusb_control_setup class in _libusb1.py uses _pack_ = 1 but does not declare _layout_.
Expected behavior
import usb1 should succeed without warnings on Python 3.14+.
Suggested fix:
Add _layout_ = "ms" to libusb_control_setup (if MSVC-compatible layout is intended), or replace _pack_ with the new layout mechanism. For example:
class libusb_control_setup(Structure):
_layout_ = "ms"
_pack_ = 1
_fields_ = [
...
]
Reproduction:
Import module running Python with warnings as errors (e.g. pytest default behavior):
python3.14 -W error::DeprecationWarning -c "import usb1"
On Python 3.14, importing usb1 raises a
DeprecationWarningthat is treated as an error, preventing the module from loading.Environment:
Traceback
Root cause:
Python 3.14 (changelog (https://docs.python.org/3.14/whatsnew/3.14.html)) deprecated the implicit behavior of
_pack_in ctypes.Structure without an explicit_layout_attribute. The libusb_control_setup class in_libusb1.pyuses_pack_ = 1but does not declare_layout_.Expected behavior
import usb1should succeed without warnings on Python 3.14+.Suggested fix:
Add
_layout_ = "ms"to libusb_control_setup (if MSVC-compatible layout is intended), or replace_pack_with the new layout mechanism. For example:Reproduction:
Import module running Python with warnings as errors (e.g. pytest default behavior):
python3.14 -W error::DeprecationWarning -c "import usb1"