mqtt_enums.CallbackAPIVersion(2) not recognized by supervisor
Describe the bug I was trying to use paho.mqtt.client to receive messages with the following code:
import paho.mqtt.client as mqtt
import paho.mqtt.enums as mqtt_enums
api_version = mqtt_enums.CallbackAPIVersion(2)
client = mqtt.Client(api_version, client_id='client_id')
I was using virtual enviroments, and the script was working.
I added it to supervisor, using the pyhton path inside the .venv folder
/home/pi/tank_level/.venv/bin/python /home/pi/tank_level/tank_level.py
and I started getting the following error message:
File "/home/pi/tank_level/tank_level.py", line 9, in <module>
import paho.mqtt.enums as mqtt_enums
ModuleNotFoundError: No module named 'paho.mqtt.enums'
The supervisor command was checked, and it worked fine outside supervisor (without the virtual enviroment activated)
Finally I reverted to v 1.6.1, changed the syntaxis and it is working perfectly.
Environment (please complete the following information): OS: Raspbian on R Pi 3+ Version : 2.1.0
Final comment There appears to be something wrong with the import of the paho.mqtt.enums library. I tried several ways of importing it, but none worked inside supervisor. It is strange that the import paho.mqtt.client works fine inside supervisor, but the next line import paho.mqtt.enums gives an error. I suggest to give api_version a default value, or to make CallbackAPIVersion easier to find
Getting the same issue in my raspberry pi environment as well, seems like the enums are not accessible for some reason. Using version 2.1 of the library
Same. version 2.1, raspberry pi, python 3.11. I tried both installing the apt package and a venv with pip install. Same issue.
Tried running example code as is as well as importing enums similar to how Client.py imporrts it. using the full package path of course.
What setup notes am I missing?
yeah
same here
this is the syntax btw
from paho.mqtt.enums import CallbackAPIVersion
CallbackAPIVersion.VERSION2
Sorry you guys are having this trouble. But for me to fix this I first need to reproduce it. Unfortunately I don't have an RPi to investigate with (just a couple of Beagles), and the bug didn't occur for me in an old Raspbian Docker image (on a big cloud server, not an RPi).
Can an RPi be emulated in Qemu, and can this be reproduced there?
So unless some other dev can pick this up, we need your help:
- On a device and in a Python run time with this bug, can
import enumbe executed without error? And canenum.Enums be used normally? - what is the Python run time exactly? Presumably it's not an official CPython from python.org. If so, we'd need to know not just the version and implementation (e.g. CPython), but either how the RPi system Python is built, or how Raspbian's package manager has repackaged Python (if it has done so at all).
On Ubuntu and Debian for example, if using the Python from the apt package manager, venvs and pip must be installed additionally. And in Indiegreg's builds of Python, various implementation details have been subtley changed.
If this bug occurs in micropython, then unfortunately I don't think micropython even provides a simplified version of the enum core library: https://github.com/micropython/micropython-lib/issues/269
Does paho.mqtt claim to support Micropython somewhere? There's no classifer for it here: https://pypi.org/project/paho-mqtt/
The reasonable enum dependence in Paho was added in commit 6f57ce9
To run Paho on MicroPython, you'll have to pin to commit 2eb5350d or an earlier version, so unfortunately unofficial Paho support for MicroPython is currently stuck on Paho from 2021 v1.6.1.
(the syntax i posted was the fix ^^ not the bug description , not sure i remember correctly , but there probably was an example somewhere that imported it from the main modules instead of the num submodule)