MQTT Python troubles


#1

Earlier this evening, I was able to execute the example code #3 from Cayenne-MQTT-Python on GitHub. However, now I’m getting “ImportError: no module named client”. Why?

cayenne-mqtt is installed using pip.


#2

Did you use sudo when installing the library with pip? Any errors during the install?


#3

Yes, I did use sudo. No errors were reported during or after the install. It’s really quite strange–it was working before. I’m working on an RPi, Debian 4.9.73+.


#4

Can you paste the output of pip freeze


#5

Here it is:

pi@raspberrypi ~ $ pip freeze

WebIOPi==0.7.23
argparse==1.2.1
cayenne-mqtt==1.0.1
cmd2==0.6.5.1
distribute==0.6.40
feedparser==5.1.3
lxml==3.2.1
nose==1.3.0
numpy==1.6.2
paho-mqtt==1.3.1
pygame==1.9.1release
pygobject==3.8.2
pyparsing==1.5.7
pyserial==2.6
python-eeml==3.2.0
virtualenv==1.9.1
wsgiref==0.1.2

pi@raspberrypi ~ $


#6

I think I’ve found the problem, but I don’t know how it could be a problem in the first place:
I made a file called “cay1.py” which has as its contents the script from example 3. In the Traceback in the Python Shell, there are two calls reported. The first one is a reference to the initial “import cayenne.client” in line 1 of “cay1.py”.

41 PM

However, the second call referred to line 34 in a completely different file in the same directory, one which I had made earlier, called cayenne.py. The interpreter somehow jumped from cay1.py to cayenne.py.

I removed all the other cayenne scripts in that directory and ran cay1.py again.

This time, it worked, without error. I think that I’m back on track, but I’m flummoxed as to why it would behave in this bizarre manner. Could it be that “cayenne.py” is reserved for the module and not meant to be “user-serviceable”?


#7

Off the top of my head I’m not sure how that works, but you can call classes, etc from files in the same directory so I would say that’s probably the issue.


#8

Thanks for your help. I’m now up and running after deleting those other files. Despite the teething issues, I’m really pleased with the relative simplicity of the Cayenne system.