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-hubpip install azure-iot-device
And I even created my own virtual environment with a fresh install and tried the same exact versions in Windows.
Update: other tests
I have tried some more things:
pip show azure-iot-hubprints the following:
Name: azure-iot-hub
(...)
Location: /usr/local/lib/python3.9/dist-packages
Requires: azure-core, msrest, uamqp
Required-by:
It seems it installs the packages on /usr/local and my python installation seems to be somewhere else:
>>> import sys
>>> print(sys.executable)
/usr/bin/python
>>> print(sys.path)
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/home/offiman/.local/lib/python3.9/site-packages', '/usr/local/lib/python3.9/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.9/dist-packages']
So I tried to move every package from /usr/local/lib/python3.9/dist-packages/ to /usr/lib/python3.9/dist-packages/. Still nothing.
- Folder
/usr/local/lib/python3.9/dist-packages/azure/iotis completely empty, seems weird.





Same issues with you on RPi4 running fresh installed Bullseye. Was not able to import azure.iot.hub modules both from python script and cmdline interrupter. While all other azure modules i.e. azure.core / azure.iot.device work find and was installed the same way as azure.iot.hub in same dir.
I tried installing the module via all different method, with/wihtout sudo, pip, pip3, python -m pip , python3 -m pip... all to make sure the its installed properly.
In my case, i end up finding the module was not actually installed in the path. And have to manually copy the source file over to fix the issues.(
/usr/local/lib/python3.9/dist-packages/azure/iot/hubis missing)python3 -m pip install azure_iot_hubpip3 list -v, in my case, i have the module located at/usr/local/lib/python3.9/dist-packages/../azure/iot/hubin the zip file, to the installation path, i.e./usr/local/lib/python3.9/dist-packages/azure/iot/hub