You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS Tahoe 26下pyUSB获取device.port_numbers返回None求助

macOS Tahoe 26.0下pyUSB的device.port_numbers返回None的问题解决思路
  • 升级依赖库版本
    pyUSB依赖libusb,macOS Tahoe 26.0的系统自带libusb可能存在兼容性问题。先通过Homebrew安装最新版libusb:

    brew install libusb
    

    同时升级pyUSB到最新稳定版:

    pip install --upgrade pyusb
    

    确保pyUSB调用的是新安装的libusb,而非系统自带版本。

  • 验证权限问题
    新系统可能收紧了USB设备的访问权限,尝试用sudo运行你的排查脚本:

    sudo python3 your_script.py
    

    如果sudo能正常获取port_numbers,说明是权限不足。可以在系统设置的「隐私与安全」中给Python添加USB访问权限,或者给脚本所在的Python进程配置对应权限。

  • 使用libusb原生API替代获取端口号
    如果上述方法无效,可以绕过pyUSB的封装,直接调用libusb的原生函数获取端口信息。示例代码如下:

    import usb.core
    import usb.backend.libusb1 as libusb_backend
    import ctypes
    
    backend = libusb_backend.get_backend()
    devices = usb.core.find(find_all=True, backend=backend)
    
    for device in devices:
        port_numbers = []
        try:
            # 先获取端口数量
            port_count = libusb_backend.libusb.libusb_get_port_numbers(device._ctx.handle, None, 0)
            if port_count > 0:
                # 分配内存存储端口号数组
                port_array = (ctypes.c_int * port_count)()
                libusb_backend.libusb.libusb_get_port_numbers(device._ctx.handle, port_array, port_count)
                port_numbers = list(port_array[:port_count])
            print(port_numbers)
        except Exception as e:
            print(f"获取端口号失败: {e}")
    
  • 排查系统USB栈底层变化
    macOS Tahoe 26.0可能对USB子系统做了底层调整,导致libusb无法正确读取端口信息。可以查看libusb的官方issue跟踪,确认是否有针对该系统版本的已知问题或修复补丁。

内容的提问来源于stack exchange,提问作者Dieter Müller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 07:42:36