【问题标题】:ModuleNotFoundError: No module named 'azure'ModuleNotFoundError:没有名为“azure”的模块
【发布时间】:2020-08-08 07:53:48
【问题描述】:

我正在尝试在我的 Windows 开发机器上运行 this 示例代码。当我尝试运行simple_send_message.py 时,我收到以下错误消息

Traceback (most recent call last):
  File "msg.py", line 3, in <module>
    from azure.iot.device.aio import IoTHubDeviceClient
ModuleNotFoundError: No module named 'azure'

开发环境详情

    PS C:\data\code\youtube\iothub\python-send-message> py --version
    Python 3.8.5

    PS C:\data\code\youtube\iothub\python-send-message>pip install azure-iot-device
    Requirement already satisfied: azure-iot-device in c:\users\heman\appdata\local\programs\python\python37-32\lib\site-packages (2.1.4)
    Requirement already satisfied: PySocks in c:\users\heman\appdata\local\programs\python\python37-32\lib\site-packages (from azure-iot-device) (1.7.1)
    Requirement already satisfied: six<2.0.0,>=1.12.0 in c:\users\heman\appdata\local\programs\python\python37-32\lib\site-packages (from azure-iot-device) (1.15.0)
    Requirement already satisfied: paho-mqtt<2.0.0,>=1.4.0 in c:\users\heman\appdata\local\programs\python\python37-32\lib\site-packages (from azure-iot-device) (1.5.0)
    Requirement already satisfied: requests-unixsocket<1.0.0,>=0.1.5 in c:\users\heman\appdata\local\programs\python\python37-32\lib\site-packages (from azure-iot-device) (0.2.0)
    Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>1.21.1; python_version != "3.4" in c:\users\heman\appdata\roaming\python\python37\site-packages (from azure-iot-device) (1.24.2)
    Requirement already satisfied: requests<3.0.0,>=2.20.0 in c:\users\heman\appdata\roaming\python\python37\site-packages (from azure-iot-device) (2.21.0)
    Requirement already satisfied: janus==0.4.0; python_version >= "3.5" in c:\users\heman\appdata\local\programs\python\python37-32\lib\site-packages (from azure-iot-device) (0.4.0)
    Requirement already satisfied: certifi>=2017.4.17 in c:\users\heman\appdata\roaming\python\python37\site-packages (from requests<3.0.0,>=2.20.0->azure-iot-device) (2019.3.9)
    Requirement already satisfied: idna<2.9,>=2.5 in c:\users\heman\appdata\roaming\python\python37\site-packages (from requests<3.0.0,>=2.20.0->azure-iot-device) (2.8)
    Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\heman\appdata\roaming\python\python37\site-packages (from requests<3.0.0,>=2.20.0->azure-iot-device) (3.0.4)

PS C:\data\code\youtube\iothub\python-send-message> python --version
Python 3.7.1
PS C:\data\code\youtube\iothub\python-send-message> pip --version
pip 20.2.1 from c:\users\heman\appdata\local\programs\python\python37-32\lib\site-packages\pip (python 3.7)
PS C:\data\code\youtube\iothub\python-send-message>

我看到couple of 线程讨论相同的问题,但不确定解决方案是什么。

任何指针,如何在 Windows 机器上解决这个问题?

【问题讨论】:

    标签: python python-3.x azure azure-iot-hub azure-iot-sdk


    【解决方案1】:

    检查安装

    请使用以下命令检查您设备上的 Python 和 pip 安装:

    python --versionpython3 --version

    pip --version


    安装在目录下

    如果一切顺利,试试这个: 尝试在你的项目目录中安装包,这里是azure。这可能会奏效。例如:

    $ cd [Project-Folder]

    pip install azure-iot-device

    【讨论】:

    • 我已经用更多信息更新了我的帖子。但仍然没有运气。
    • 非常非常抱歉的朋友。我是 Mac 和 Linux 用户。
    【解决方案2】:

    你能用 pip3 试试吗?

    pip3 install azure-iot-device
    

    【讨论】:

    • 是的,我已经尝试过使用 pip3。看起来我的 Windows 无法处理多个版本的 Python。同样的事情在我的 Raspberry Pi 设备上运行良好,没有任何问题
    猜你喜欢
    • 2023-01-31
    • 2019-03-28
    • 1970-01-01
    • 2022-01-07
    • 2021-03-07
    • 2017-12-14
    • 2020-12-10
    • 2021-09-02
    相关资源
    最近更新 更多