I’m having an issue trying to execute a very simple python script that works perfectly in Windows but not on my Le Potato (Debian):
import uuid
from azure.iot.hub import IoTHubRegistryManager
import MqttClient as mqttClient
CONNECTION_STRING = "HostName=(...)"
DEVICE_ID = "(...)"
registry_manager = IoTHubRegistryManager(CONNECTION_STRING)
def send_message(msg):
props = {}
props.update(messageId = str(uuid.uuid4()))
props.update(contentType = "application/json")
props.update()
registry_manager.send_c2d_message(DEVICE_ID, msg, properties=props)
def on_message(mqttc, obj, msg):
print("[" + msg.topic+"]: "+str(msg.payload))
try:
send_message(str(msg.payload))
except Exception as e:
print("An exception occurred:", str(e))
mqttClient.init(on_message=on_message)
When running python myscript.py
I get the error ModuleNotFoundError: No module named 'azure.iot.hub'
I installed everything several times:
-
pip install azure-iot-hub
-
pip install azure-iot-device
And I even created my own virtual environment with a fresh install and tried the same exact versions in Windows.
2
Answers
Using this reference MSDOC able to Send cloud-to-device messages.
pip install azure-iot-hub
,pip3 install azure-iot-hub
andpip3 install uuid
pip list
we can check the respective module is installed .Code:
Output:
Code:
Output:
linux see root and non-root as different users, are you running your python code at the same user you installed these dependencies?
for example if you run it by sudo, you need to reinstall those libraries on root too.