mjmccans / airthings-mqtt-ha

Python script for Airthings devices that uses mqtt to integrate with Home Assistant via mqtt discovery.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No module named 'paho'

dwlyles opened this issue · comments

I'm getting the following error even though i have paho-mqtt installed via pip3

Requirement already satisfied: paho-mqtt in /home/pi/.local/lib/python3.10/site-packages (1.6.1)

Traceback (most recent call last): File "/home/pi/airthings-mqtt-ha/src/./airthings-mqtt-ha.py", line 24, in <module> import paho.mqtt.publish as publish ModuleNotFoundError: No module named 'paho'

I am running Ubunut 22.04 (jammy) on rpi3.

I am by no means an expert in pip, but it looks like your python interpreter is not seeing the installed paho package. One simple test would be to run "python3" at the command line and then try "import paho" at the ">>>" prompt. If there is no error then the module imported correctly.

Another thought is that it looks like the paho package was installed in the "pi" user's home directory (i.e., using the --user option when installed) so it will only be available to the pi user. Are you running the script as the pi user?

Hopefully we can figure out what the issue is and get you up and running.

If I remember correctly the bluetooth stuff needs sudo to run, so you will need to install paho without the --user option.

You can definitely install the modules globally, but you do not need to run as root provided you have run setcap on the bluepy-helper binary as follows:

sudo setcap 'cap_net_raw,cap_net_admin+eip' `find ~/.local/lib/ | grep bluepy-helper | grep -v bluepy-helper.c`

It has been a while, but my recollection is that root access is only needed for bluetooth scanning and not where you know the device's mac address, so you could also just run the script as root for scanning purposes and then revert to a non-privileged user.

If I remember correctly the bluetooth stuff needs sudo to run, so you will need to install paho without the --user option.

I ultimately decided last night to go back to raspbian instead of ubuntu, but i started to have the same issue.
So i it looks like since i cant run the /airthings-mqtt-ha.py --generate_config without root. installing the pip3 packages as root and it worked, but somewhere in there not running root works too so im not sure what happened.

I did run the sudo setcap 'cap_net_raw,cap_net_admin+eip' find ~/.local/lib/ | grep bluepy-helper | grep -v bluepy-helper.c`` again with verbose to make sure it was "OK"

Everything works now as planned.
Thanks for your imput, i appreciate it!