Page 1 of 1

No module named 'serial'

Posted: Wednesday 30 October 2019 9:49
by RobD
Version: V4.10717
Platform Pi 3B+ (stretch and buster)

I have a piece of Python3 code that uses the serial library.
I imported this library with sudo apt-get install python3-serial
the code is placed in .../domoticz/scripts/python/script_time_test.py to activate it every minute bij de Domoticz scheduler.
The code contains at this moment only import commands

Code: Select all

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import datetime
import json
import os.path
import shutil
import threading
import time
import serial
If I run this piece of code in Thonny all libraries are imported without problems.
However if the Domotics sceduler starts the scripts, all standard libraries that come with the raspbian distribution are imported without problems but the serial library ends up with the error
2019-10-29 09:37:00.162 Error: EventSystem: Failed to execute python event script "/home/pi/domoticz/scripts/python/script_time_VirtDev.py"
2019-10-29 09:37:00.162 Error: EventSystem: Traceback (most recent call last):
2019-10-29 09:37:00.162 Error: EventSystem: File "/home/pi/domoticz/scripts/python/script_time_VirtDev.py", line 10, in <module>
2019-10-29 09:37:00.162 Error: EventSystem: import serial
2019-10-29 09:37:00.162 Error: EventSystem: ImportError: No module named 'serial'
How is domoticz starting the scripts in the .../scripts/python directory?
Does domoticz honour my choice of python interpreter specified in the script, or does it impose its own choice of interpreter?

Re: No module named 'serial'

Posted: Friday 08 November 2019 13:56
by RobD
In the mean time tried to import the scipy library. result is the same, the library is not installed.
it looks like the environment where domoticz is starting the scripts does not have access to the manually installed modules.
the serial library is in

Code: Select all

/usr/lib/python3/dist-packages/serial
I compared the PATH variables of the Thonny and the Domoticz environment. although there are differences, nothing points in this direction.
with Thonny the code is run under user pi, Domoticz runs the scripts with user root.

where more can I look?