Python3.11+macOS Sonoma安装azure-iot-hub失败,求修复或替代方案
问题场景
设备配置:Apple M2 Max芯片、macOS Sonoma 14.3.1系统、Python 3.11版本
尝试安装azure-iot-hub包时,因依赖的uamqp编译失败,核心错误为函数指针类型不兼容,具体编译日志如下:
(venv) user@userxxxx % pip install azure-iot-hub Collecting azure-iot-hub Using cached azure_iot_hub-2.6.1-py2.py3-none-any.whl.metadata (2.2 kB) Collecting msrest<1.0.0,>=0.6.21 (from azure-iot-hub) Using cached msrest-0.7.1-py3-none-any.whl.metadata (21 kB) .. .. .. Building wheels for collected packages: uamqp Building wheel for uamqp (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for uamqp (pyproject.toml) did not run successfully. │ exit code: 1 .. .. .. uamqp/c_uamqp.c:65557:146: error: incompatible function pointer types passing 'void (void *, enum MESSAGE_RECEIVER_STATE_TAG, enum MESSAGE_RECEIVER_STATE_TAG)' to parameter of type 'ON_MESSAGE_RECEIVER_STATE_CHANGED' (aka 'void (*)(const void *, enum MESSAGE_RECEIVER_STATE_TAG, enum MESSAGE_RECEIVER_STATE_TAG)') [-Wincompatible-function-pointer-types] __pyx_t_1 = ((struct __pyx_vtabstruct_5uamqp_7c_uamqp_cMessageReceiver *)__pyx_v_receiver->__pyx_vtab)->create(__pyx_v_receiver, __pyx_v_link, __pyx_f_5uamqp_7c_uamqp_on_message_receiver_state_changed, ((void *)__pyx_v_callback_context)); if (unlikely(!__pyx_t_1)) __PYX_ERR(7, 23, __pyx_L1_error) .. .. .. 35 warnings and 1 error generated. error: command '/usr/bin/clang' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for uamqp Failed to build uamqp ERROR: Could not build wheels for uamqp, which is required to install pyproject.toml-based projects
已知azure-iot-hub包已两年未维护,以下是可行的修复方案和替代包推荐:
修复方案
- 降级Python版本:切换到Python 3.9或3.10版本,旧版本Python与
uamqp的兼容性更好,可绕过编译时的函数指针类型不兼容问题。 - 指定兼容的
uamqp版本:先安装带有Apple Silicon预编译轮子的uamqp旧版本,再安装azure-iot-hub,命令如下:pip install uamqp==1.6.3 pip install azure-iot-hub - 忽略编译警告:安装时添加编译参数,让clang跳过函数指针不兼容的错误检查,命令:
CFLAGS="-Wno-incompatible-function-pointer-types" pip install azure-iot-hub
替代包推荐
azure-iot-device:微软官方维护的IoT设备端SDK,支持与IoT Hub的核心交互(发送遥测消息、接收云到设备命令、设备孪生操作等),更新频繁,完美兼容Apple Silicon和Python 3.11。azure-mgmt-iothub:如果你的需求是管理IoT Hub资源(如创建设备、配置路由规则、调整Hub规模),推荐使用这个官方管理类SDK,无编译依赖问题,维护活跃。
内容的提问来源于stack exchange,提问作者VidyaV
相关产品推荐
相关产品推荐

