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


#1

Hello,
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/device.py” 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!


#2

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:

https://onion.io/2bt-single-command-losantomega/


#3

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?


#4

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


#5

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.


#6

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

Thanks for the doc and pip!


#7

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


#8

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.

https://docs.losant.com/applications/overview/#communication-log


#9

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 setup.py egg_info" failed with error code 1 in /tmp/pip-build-YJGsbF/paho-mqtt/. How can I fix this problem?

Thanks!