Thanks! It works now. Next time I’ll open separate topic.
Oddly, this didn’t work for me. When issuing the command, I get
[12:29:49] openhabian@openhab:~$ sudo -u openhab pip2 install --ignore-installed --install-option="--prefix=/etc/openhab2/automation/lib/python" requests
[sudo] password for openhabian:
/usr/lib/python2.7/dist-packages/pip/_internal/commands/install.py:222: UserWarning: Disabling all use of wheels due to the use of --build-options / --global-options / --install-options.
cmdoptions.check_install_build_global(options)
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting requests
Downloading https://files.pythonhosted.org/packages/da/67/672b422d9daf07365259958912ba533a0ecab839d4084c487a5fe9a5405f/requests-2.24.0.tar.gz (115kB)
100% |████████████████████████████████| 122kB 942kB/s
Collecting certifi>=2017.4.17 (from requests)
Downloading https://files.pythonhosted.org/packages/40/a7/ded59fa294b85ca206082306bba75469a38ea1c7d44ea7e1d64f5443d67a/certifi-2020.6.20.tar.gz (157kB)
100% |████████████████████████████████| 163kB 958kB/s
Collecting chardet<4,>=3.0.2 (from requests)
Using cached https://files.pythonhosted.org/packages/fc/bb/a5768c230f9ddb03acc9ef3f0d4a3cf93462473795d18e9535498c8f929d/chardet-3.0.4.tar.gz
Collecting idna<3,>=2.5 (from requests)
Using cached https://files.pythonhosted.org/packages/cb/19/57503b5de719ee45e83472f339f617b0c01ad75cba44aba1e4c97c2b0abd/idna-2.9.tar.gz
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
Using cached https://files.pythonhosted.org/packages/05/8c/40cd6949373e23081b3ea20d5594ae523e681b6f472e600fbc95ed046a36/urllib3-1.25.9.tar.gz
Skipping bdist_wheel for requests, due to binaries being disabled for it.
Skipping bdist_wheel for certifi, due to binaries being disabled for it.
Skipping bdist_wheel for chardet, due to binaries being disabled for it.
Skipping bdist_wheel for idna, due to binaries being disabled for it.
Skipping bdist_wheel for urllib3, due to binaries being disabled for it.
Installing collected packages: certifi, chardet, idna, urllib3, requests
Running setup.py install for certifi ... done
Running setup.py install for chardet ... done
Running setup.py install for idna ... done
Running setup.py install for urllib3 ... done
Running setup.py install for requests ... done
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.9 requests-2.24.0 urllib3-1.25.9
Now, adding import requests
into a script yields this error in the openhab log:
2020-06-21 12:32:35.246 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/default.py': ImportError: No module named requests in <script> at line number 12
What do you see in /etc/openhab2/automation/lib/python/, and what do you see in sys.path? I recently added a script that may be helpful (not in add-on yet)…
This is the output of 000_startup.py:
2020-06-22 20:58:27.912 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/core/000_startup.py'
2020-06-22 20:58:28.048 [WARN ] [jython.Startup ] -
*******************************************************************************
Jython version: 2.7.0.final
Operating system: Linux
OS Version: 4.19.97-v7l+
Java vendor: Azul Systems, Inc.
Java VM name: OpenJDK Client VM
Java runtime name: OpenJDK Runtime Environment
Java runtime version: 1.8.0_252-b225
sys.path: /etc/openhab2/automation/lib/python
/var/lib/openhab2/cache/org.eclipse.osgi/203/0/bundleFile/Lib
__classpath__
__pyclasspath__/
*******************************************************************************
Not sure I’m on the latest beta version… The directory I copied 000_startup.py to had the file 000_startup_delay.py for my installation. This file is not in this folder in GitHub…
And this is the lib/python directory:
[20:57:23] openhabian@openhab:~$ ls -axl /etc/openhab2/automation/lib/python
total 36
drwxr-xr-x 5 openhabian openhab 4096 May 7 12:50 .
drwxr-xr-x 4 openhabian openhab 4096 May 7 12:48 ..
-rw-r--r-- 1 openhabian openhab 1499 Jan 28 14:42 bolbro.py
drwxr-xr-x 2 openhabian openhab 4096 Dec 8 2019 community
-rw-r--r-- 1 openhabian openhab 148 Jan 17 12:31 configuration.py
drwxr-xr-x 3 openhabian openhab 4096 Dec 8 2019 core
drwxr-xr-x 2 openhabian openhab 4096 Jan 18 16:56 personal
bolbro.py is a module that probably should be in personal.
The scripts are currently copied from the repo manually and periodically need to be copied again to get the latest. I have updated some scripts recently and the 000_startup_delay.py script has been removed. I haven’t seen a need for this script in a long while, so you could remove it. This may need to go back in if people report issues with it not being there, which may be the case for people running DSL rules too. I will create a release when the updates are all pushed, update the beta Jython addon, and then get some forum posts out. I am working on including the core scripts inside the addon, to make updates easier.
It does not look like requests and its dependencies were installed into /etc/openhab2/automation/lib/python. If you find where it went, just copy it in there. You could also copy it from your Python2 directory. Please open a new topic to discuss further, as this does not pertain to the addon.
I have created a new topic here: Installing external modules to jython beta
I will try the straight copy for one of the instances found but hope to get this sorted out in general.
@5iver Scott, installed the bundle on a new OH install (2.5.6) and am getting the error below when the date module is imported.
2020-07-02 17:57:55.712 [ERROR] [eclipse.smarthome.model.script.Rules] - Traceback (most recent call last):
File "<script>", line 8, in <module>
File "/etc/openhab2/automation/lib/python/personal/occupancy/occupancy_manager.py", line 28, in <module>
import personal.occupancy.areas.area_manager
File "/etc/openhab2/automation/lib/python/personal/occupancy/areas/area_manager.py", line 13, in <module>
import personal.occupancy.areas.area
File "/etc/openhab2/automation/lib/python/personal/occupancy/areas/area.py", line 22, in <module>
from core.date import seconds_between
File "/etc/openhab2/automation/lib/python/core/date.py", line 43, in <module>
from org.openhab.core.library.types import DateTimeType as LegacyDateTimeType
ImportError: No module named library
Try running this script and post the log…
I can’t reproduce this, with or without a 1.x binding installed.
Results
\*******************************************************************************
\ Jython version: 2.7.0.final
\ Operating system: Linux
\ OS Version: 4.19.97-v7l+
\ Java vendor: Azul Systems, Inc.
\ Java VM name: OpenJDK Client VM
\ Java runtime name: OpenJDK Runtime Environment
\ Java runtime version: 1.8.0_252-b225
\ sys.path: /etc/openhab2/automation/lib/python
/var/lib/openhab2/cache/org.eclipse.osgi/204/0/bundleFile/Lib
__classpath__
__pyclasspath__/
\ *******************************************************************************
This code
import traceback
from org.slf4j import Logger, LoggerFactory
log = LoggerFactory.getLogger("org.eclipse.smarthome.model.script.Rules")
try:
from core.date import seconds_between
except:
log.error (traceback.format_exc())
results in
File "<script>", line 14, in <module>
File "/etc/openhab2/automation/lib/python/core/date.py", line 43, in <module>
from org.openhab.core.library.types import DateTimeType as LegacyDateTimeType
ImportError: No module named library
This works fine on my Jython install done manually, not using this bundle. Thoughts?
I setup a fresh 2.5.6, added ruleengine to addions.cfg, the beta jar, a configuration.py, this test script, and I do not get an error. Maybe you are using an older version of the jar?
I used the link at the top of thread… is that the latest?
Yes, but the file has been updated at least a couple times. What is the date of the jar?
correction - I had one from Jan
So I did a manual install of Jython and same problem. Weird.
2020-07-05 11:35:32.134 [ERROR] [eclipse.smarthome.model.script.Rules] - Traceback (most recent call last):
File "<script>", line 14, in <module>
File "/etc/openhab2/automation/lib/python/core/date.py", line 43, in <module>
from org.openhab.core.library.types import DateTimeType as LegacyDateTimeType
ImportError: No module named library
2020-07-05 11:35:32.137 [WARN ] [jython.Startup ] -
\*******************************************************************************
\ Jython version: 2.7.2.final
\ Operating system: Linux
\ OS Version: 4.19.97-v7l+
\ Java vendor: Azul Systems, Inc.
\ Java VM name: OpenJDK Client VM
\ Java runtime name: OpenJDK Runtime Environment
\ Java runtime version: 1.8.0_252-b225
\ sys.path: /etc/openhab2/automation/lib/python
/etc/openhab2/automation/jython/Lib
/etc/openhab2/automation/jython/jython-standalone-2.7.2.jar/Lib
__classpath__
__pyclasspath__/
\ *******************************************************************************
Is that with your script or test script or both? What happens if you remove all scripts and create a new one, without copy/paste? Maybe there’s a nonprintable character hidden in there.
Or post your script (just put .txt at the end of the name).
After the update to 2.5.6-2 jython was not started anymore. Only Javascript…
I had no clue. Removed nrge. Reinstalled it. Restarted opengaan. Nothing. Tried this a few times, including a complete reboot. Javascript engine started, nut no jython. Since i don’t Knox how the engine is started, i thought, i’ll look at the path. And, it was gone! I added the path, restarted OH. And up and running!
I thought an install of nrge was taking Care of the path? Anyway, everthing works again
@Suy, then you are not using the Jython add-on. Remove the core and community libraries from $OPENHAB_HOME/lib/python/, remove the Jython entries in EXTRA_JAVA_OPTS, and copy the jar to $OPENHAB_HOME/add-ons. If you don’t want to use the add-on, then please start a new topic.
I have been using the jython library almost from beginning and had long had the plan for trying this beta. Finally I decided to spent an evening spinning it all up. Previously the setup anything from straightforward. I decided to spin up a fresh install of openHAB on a fresh installed Ubuntu 20.04 Server.
The short story is that it went well and it was amazingly easy to setup. Only thing that I had problems with, was that I actually did to much configuring (EXTRA_OPTS), after some searching I found a thread where it was stated what to leave out from the usual config. After that it just started.
I have just copied the community scripts from the repo and my personal scripts from my current openHAB insatll, and its seems to work (no errors in the log)
Great work, I actually decided to use this new server for production, so I will for sure look into it. But it really looks good, and it seems to be quite easy to setup