Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named mosquitto

I have installed mosquitto on Ubuntu 15.10 using the following command

sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
sudo apt-get update

To check if Mosquitto is installed i type mosquitto and it shows all the details as follows:

1458716686: mosquitto version 1.4.8 (build date Sun, 14 Feb 2016 15:48:26 +0000) starting
1458716686: Using default config.
1458716686: Opening ipv4 listen socket on port 1883.
1458716686: Opening ipv6 listen socket on port 1883.

Which implies mosquitto is working right?

So i proceed with my program written in python. (Pyton version 2.7)

import mosquitto
mqttc = mosquitto.Mosquitto("python_pub")
mqttc.will_set("/event/dropped", "Sorry, I seem to have died.")
mqttc.connect("127.0.0.1", 1883, 60, True)
mqttc.publish("hello/world", "Hello, World!")

On running the above program i get this error

ImportError: No module named mosquitto

I am new to the whole mqtt concept. Please let me know where i went wrong

like image 493
Uswer721 Avatar asked Jun 01 '26 15:06

Uswer721


2 Answers

The mosquitto python module is no longer part of the Eclipse Mosquitto project, it has moved to the Eclipse Paho project instead.

You can install it with pip install paho-mqtt or pip3 install paho-mqtt.

You could then do:

import paho.mqtt as paho
mqttc = paho.Client()
...

The remainder of the API is largely the same, it has just been expanded and improved.

like image 103
ralight Avatar answered Jun 03 '26 05:06

ralight


http://www.eclipse.org/paho/clients/python/ says:

import paho.mqtt.client as mqtt
client = mqtt.Client()

check another code

like image 28
dontsov Avatar answered Jun 03 '26 05:06

dontsov