在 Python 3.11 macOS Sonoma 上安装 azure-iot-hub 时出错。寻求修复或替代方案?

问题描述 投票:0回答:1

我在 Apple M2 Max 和 macOS Sonoma 版本 14.3.1 上使用 Python 3.11。我在尝试安装

azure-iot-hub
时遇到了这个错误,因为
uamqp
是一个依赖项。这里提到了这个问题:https://github.com/ansible-collections/azure/issues/1511。我正在寻找
azure-iot-hub
软件包的任何修复或替代方案,因为到目前为止它也没有维护 2 年。

(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
python azure azure-iot-hub pypi python-wheel
1个回答
0
投票

在 Python 3.11 macOS Sonoma 上安装 azure-iot-hub 时出错。寻求修复或替代方案?

由于

azure-iot-hub

 依赖项构建失败,尝试安装 
uamqp
 包时出现 
问题。这可能与 Python 3.11 或 macOS Sonoma 的兼容性问题有关。

  • 将依赖项(包括
    pip
    setuptools
    wheel
    )更新到最新版本。有时,过时的依赖项可能会导致构建问题。
python3 -m venv myenv
source myenv/bin/activate
pip install --upgrade pip setuptools wheel

您可以尝试使用其他方法安装软件包,而不是使用

pip
,例如
conda
(如果您安装了 Anaconda 或 Miniconda):

conda install -c conda-forge azure-iot-hub
  • 另一种方法是使用
    azure-mgmt-iothub

使用 Azure IoT Python SDK 发送消息的代码

from azure.iot.device import IoTHubDeviceClient, Message
import random

CONNECTION_STRING = "YourDeviceConnectionString"
MESSAGE_TEMPLATE = "boogie_{}={}"

# Create an instance of the device client using the connection string
device_client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)

# Connect the device client
device_client.connect()

# Send 12 "boogie" messages with random numbers
for i in range(1, 13):
    value = random.randint(0, 150)
    message = Message(MESSAGE_TEMPLATE.format(i, value))
    device_client.send_message(message)
    print("Sent message: " + MESSAGE_TEMPLATE.format(i, value))

# Disconnect the device client
device_client.disconnect()

enter image description here

使用 Azure CLI 监视来自 Azure IoT 中心的事件

 az iot hub monitor-events --hub-name HubName    --device-id deviceid -g resoursegroupname

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.