I am trying to use the cec PIP package found here. I have the following code in $OPENHAB_CONF/automation/jsr223/python/personal/test_cec_command.py:
#!/usr/bin/python
import cec
cec.init()
tv = cec.Device(cec.CECDEVICE_TV)
tv.power_on()
This gives the error output in the logs, because it cannot find the cec package:
2020-04-01 20:57:29.453 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/test_cec_command.py': ImportError: No module named
cec in <script> at line number 3
I did install it and running it as openhabe user works as expected:
… or copy the package manually from wherever it was installed on your system
… or create a symlink to the package
… or add the Python2 packages directory to the python.path
So does does this mean the installation methods that @5iver just suggested, will only result in a non-working package, when I try using it? (using the package I meant, if I get it to install …)
You need the library and compile parts listed on the GitHub page. Perhaps you somehow need to symlink Jython so it appears as Python 2.
Even that that may still not work, especially sonce the project says it has not been verified on a Pi,
Have you tried running the script in Jython? Files with a .py extension will be associated with Python (plus you have a #!), so you’d need to either run it from a Jython console or use…
That makes sense. I am completely new to Jython. I don’t even have the jython command in my path:
$ sudo -u openhab jython test_cec_command.py
sudo: jython: command not found
Do I need to configure something for this? Perhaps I should do some long reading before continuing. Perhaps you could point me to an entry point to some relevant resources (Jython related and OpenHAB specific)? That’d be great!
How did you install it? If you used a standalone jar, then there’s more that you could do. However, if you are new to Jython/Python, then I think it would be best to back up and keep things simple. Once the package is in the python.path, you can run it through OH (if it is compatible with Jython). BTW, Jython 2.7.2 had been released and has better compatibility.
I did not install Jython at all. I thought, that since OpenHAB uses it, it is installed. But now I realize I did not install any package for it. It was just the JAR. I am somewhat familiar with Python BTW - just not Jython.
I will try adding the package to python.path. It is currently located here:
This may help you with the install of Jython and the helper libraries…
I’ve done some work on this lately to move the bundle to openhab-addons rather than openhab-core and to split out the helper libraries. The new version uses 2.7.2 and is working great.