I am trying to call a python script from an OpenHAB rule. My problem now is that if the script is executed from a rule, it does not find its imports:
File “/home/openhabian/leaf-python-mqtt/leaf-python-mqtt-1.py”, line 6, in
ImportError: No module named pycarwings2
When started manually from a putty window (logged in with the openhabian user), the script works. The script is located in /home/openhabian/.local/lib/python2.7/site-packages/pycarwings2.
Any idea why this happens ? I assume OpenHAB is running under the openhabian user as well and should have the same sys.path ?
I am running OpenHAB 2.5.9 on a Raspberry Pi4, openhabian, minimal install.
the pycarwings2 library is installed both in python 2 and 3, so that should not be the reason (if I get your answer right). There must be a difference in the ‘environment’ that OpenHAB uses and that console windows use. But I have no idea why …
Did you install any addons to be able to call python scripts ?
If you enjoy using Python and native rule engines, you might want to look into the new rule engine. which includes scripted automation. This rule engine was labelled the Next Generation Rule Engine and marked as experimental in OH2, but it is now the only rule engine officially available in OH3. With scripted automation, you can use Jython and the helper libraries, which can use directly use Java, OH classes and services, and the OH automation API, rather than using the REST API (slower and limited functionality).