No module named "paho.mqtt" error when importing "losantmqtt" python module


I’m new to the Losant platform, and recently I’ve been working through the getting started guide for using Losant and the Onion Omega2 (Getting Started with Onion Omega2 and Losant Using Python). As the title suggests I ran into a Python ImportError, the “paho.mqtt” module was not found. The module’s import was traced back from the “losantmqtt” module to the “losantmqtt/” file with the module import request from paho.mqtt import client as mqtt.
How would I solve this problem? Would something like pip paho.mqtt work?
I’ve followed everything from the tutorial exactly, including git cloning the example code files and “losantmqtt” module from GitHub.

Thank you in advance for your help!


Hi @Microbob!

Yes, installing it via pip should work. I’ll add that to the tutorial. I’m sorry that was missing!

However, Onion just released a new way to integrate Losant and the Omega. Check this out:

1 Like

Sounds Good! Thank you so much for helping me and the Single Command 2bt post!

Out of curiosity, what would be the correct pip command?


Would there be a second authentication system needed apart from the app key and secret? After typing in the mosquitto_sub command, I get a refused connection: Error: Connection refused


There is an example installing the module on their docs :slight_smile:

But, it’s just:

pip install paho-mqtt

And for the startup script command, you need to provide a device ID, key, and secret. All three are required for proper authentication.


I got that part, but it still through the connection refused error.

Thanks for the doc and pip!


With the pip command, your tutorial worked! :smile:


Woo Hoo! That’s awesome. The blog post is updated.

Also, for future reference( if you try the script again) take a look at the communication log. You should see some helpful message there if the connection is reaching Losant.


Hello again,
Strangely, I have ran into another issue with installing paho-mqtt. I needed to install paho-mqtt again (on a different device), so i did it with the command on the (updated) tutorial: pip install paho-mqtt. It ran into an error though while installing: Command "python egg_info" failed with error code 1 in /tmp/pip-build-YJGsbF/paho-mqtt/. How can I fix this problem?