Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error File "daemon.py", line 11, in <module> import paho.mqtt.client as paho ModuleNotFoundError: No module named 'paho' Solved #18

Open
tonbor opened this issue Nov 6, 2024 · 2 comments

Comments

@tonbor
Copy link

tonbor commented Nov 6, 2024

Files:
pi@raspberrypi:/opt/kamstrup $ ls
config.yaml daemon.py kamstrup_meter.py kamstrup_meter.pyc mqtt_handler.py

pi@raspberrypi:/opt/kamstrup $ pip install pyserial
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pyserial in /usr/lib/python2.7/dist-packages (3.4)
pi@raspberrypi:/opt/kamstrup $ pip install paho-mqtt
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: paho-mqtt in /usr/local/lib/python2.7/dist-packages (1.6.1)
pi@raspberrypi:/opt/kamstrup $ pip install PyYAML
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: PyYAML in /usr/local/lib/python2.7/dist-packages (5.4.1)
pi@raspberrypi:/opt/kamstrup $ python3 daemon.py &
[1] 1771
pi@raspberrypi:/opt/kamstrup $ Traceback (most recent call last):
File "daemon.py", line 11, in
import paho.mqtt.client as paho
ModuleNotFoundError: No module named 'paho'

after update paho-mqtt new error
pi@raspberrypi:/opt/kamstrup $ Traceback (most recent call last):
File "daemon.py", line 13, in
import yaml
ModuleNotFoundError: No module named 'yaml'

sudo -H pip3 install --ignore-installed PyYAML
update PyYAML to 6.01

pi@raspberrypi:/opt/kamstrup $ python3 daemon.py &
[1] 2778
pi@raspberrypi:/opt/kamstrup $ Traceback (most recent call last):
File "daemon.py", line 22, in
handler = TimedRotatingFileHandler('logs/debug.log', when="d", interval=1, b ackupCount=5)
File "/usr/lib/python3.7/logging/handlers.py", line 199, in init
BaseRotatingHandler.init(self, filename, 'a', encoding, delay)
File "/usr/lib/python3.7/logging/handlers.py", line 54, in init
logging.FileHandler.init(self, filename, mode, encoding, delay)
File "/usr/lib/python3.7/logging/init.py", line 1092, in init
StreamHandler.init(self, self._open())
File "/usr/lib/python3.7/logging/init.py", line 1121, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/opt/kamstrup/logs/debug.log'

dir made
new error
Traceback (most recent call last):
File "daemon.py", line 85, in
main()
File "daemon.py", line 81, in main
daemon = KamstrupDaemon()
File "daemon.py", line 59, in init
self.mqtt_handler.connect()
File "/opt/kamstrup/mqtt_handler.py", line 28, in connect
self.mqtt_client = paho.Client(paho.CallbackAPIVersion.VERSION1, self.client_id, True)
AttributeError: module 'paho.mqtt.client' has no attribute 'CallbackAPIVersion'

@tonbor
Copy link
Author

tonbor commented Nov 7, 2024

Ok got it working with a change
#self.mqtt_client = paho.Client(paho.CallbackAPIVersion.VERSION1, self.client_id, True)
to-> self.mqtt_client = paho.Client(self.client_id, True)
Got one message to mqtt then:

new error
pi@raspberrypi:/opt/kamstrup $ python3 daemon.py &
[3] 20220
pi@raspberrypi:/opt/kamstrup $ Traceback (most recent call last):
File "daemon.py", line 85, in
main()
File "daemon.py", line 82, in main
daemon.run()
File "daemon.py", line 75, in run
self.mqtt_handler.publish("values", str(values).replace("'", """))
File "/opt/kamstrup/mqtt_handler.py", line 50, in publish
mqtt_info.wait_for_publish()
File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 3 62, in wait_for_publish
raise RuntimeError('Message publish failed: %s' % (error_string(self.rc)))
RuntimeError: Message publish failed: The client is not currently connected.

debug log:
2024-11-07 08:15:32 daemon.py init: 34 - INFO - initializing daemon]
[2024-11-07 08:15:32 mqtt_handler.py connect: 36 - INFO - Connected to MQTT at: 192.168.x.xx:1883]
[2024-11-07 08:15:32 mqtt_handler.py connect: 38 - INFO - QoS level = 0 and retain = False]
[2024-11-07 08:15:32 kamstrup_meter.py close: 126 - DEBUG - Closed serial port]
[2024-11-07 08:15:32 kamstrup_meter.py open: 118 - DEBUG - Opened serial port]
[2024-11-07 08:15:33 kamstrup_meter.py close: 126 - DEBUG - Closed serial port]
[2024-11-07 08:15:33 mqtt_handler.py publish: 48 - INFO - Publishing 'kamstrup/values' '{"energy": 23.499, "volume": 136.029, "temp1": 71.06, "temp2": 23.46}' to 192.168.x.xx:1883]
[2024-11-07 08:16:10 daemon.py init: 34 - INFO - initializing daemon]
[2024-11-07 08:16:10 mqtt_handler.py connect: 36 - INFO - Connected to MQTT at: 192.168.x.xx:1883]
[2024-11-07 08:16:10 mqtt_handler.py connect: 38 - INFO - QoS level = 0 and retain = False]
[2024-11-07 08:16:11 kamstrup_meter.py close: 126 - DEBUG - Closed serial port]
[2024-11-07 08:16:11 kamstrup_meter.py open: 118 - DEBUG - Opened serial port]
[2024-11-07 08:16:11 kamstrup_meter.py close: 126 - DEBUG - Closed serial port]
[2024-11-07 08:16:11 mqtt_handler.py publish: 48 - INFO - Publishing 'kamstrup/values' '{"energy": 23.5, "volume": 136.03300000000002, "temp1": 71.42, "temp2": 23.27}' to 192.168.x.xx:1883]

solved was the clock, cannot run twice deamon

@tonbor tonbor changed the title Error File "daemon.py", line 11, in <module> import paho.mqtt.client as paho ModuleNotFoundError: No module named 'paho' Error File "daemon.py", line 11, in <module> import paho.mqtt.client as paho ModuleNotFoundError: No module named 'paho': Solved Nov 7, 2024
@tonbor tonbor changed the title Error File "daemon.py", line 11, in <module> import paho.mqtt.client as paho ModuleNotFoundError: No module named 'paho': Solved Error File "daemon.py", line 11, in <module> import paho.mqtt.client as paho ModuleNotFoundError: No module named 'paho' Nov 7, 2024
@tonbor tonbor changed the title Error File "daemon.py", line 11, in <module> import paho.mqtt.client as paho ModuleNotFoundError: No module named 'paho' Error File "daemon.py", line 11, in <module> import paho.mqtt.client as paho ModuleNotFoundError: No module named 'paho' Solved Nov 7, 2024
@tonbor
Copy link
Author

tonbor commented Nov 7, 2024

For all people that try the same as me................

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant