Python cayenne-mqtt: No module named client

I am trying to setup a python script to send some data to Cayenne from a raspberry pi 3 using the Cayenne-MQTT-Python, but I get this error:

import cayenne.
ImportError: No module named client

I also tried only importing cayenne and this is the error I got:

client = cayenne.client.CayenneMQTTClient()
AttributeError: 'module' object has no attribute 'client'

I tried running it with both python 2 and 3 with no luck.

What am I doing wrong?

How did you install the python library?

pip install cayenne-mqtt

Did you run the install with sudo? I have not tested if this library installs without it. I used the following commands and it works ok.

sudo pip install cayenne-mqtt
import cayenne.client

No errors displayed for me.

Try reinstalling the library with sudo pip install cayenne-mqtt

hmm, I don’t remember if I used sudo for that or not, I’ll test it out when I can and let you know, thanks!

1 Like

I seem to be having the same problem did this ever get resolved?

I also tried to re-install the library and still doesn’t work…

pi@raspberrypi:~ $ sudo pip install cayenne-mqtt
Requirement already satisfied: cayenne-mqtt in /usr/local/lib/python2.7/dist-packages/cayenne_mqtt-1.0.1-py2.7.egg
Requirement already satisfied: paho-mqtt>=1.0 in /usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg (from cayenne-mqtt)
pi@raspberrypi:~ $ python
Python 2.7.13 (default, Jan 19 2017, 14:48:08)
[GCC 6.3.0 20170124] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import cayenne
Traceback (most recent call last):
File “”, line 1, in
File “”, line 2, in
import cayenne.client
ImportError: No module named client

I just pulled the git repo and I used it that way…

I tried that too and didn’t work until I put my code file into the example directory. Why that makes a difference I guess I have no clue right now.

Hmm I thought I posted that, maybe it was somewhere else. Yes you must put the files in a directory outside the library folder,

do not name the folder where your py file is cayenne. when you do import module, it will check locally and python finds a folder named cayenne. it will try to use that folder as module and import from that folder.