Closed sillyfrog closed 5 years ago
This ESH issue may be related... https://github.com/eclipse/smarthome/issues/6392. I have only worked with Jython 2.7.0 in OH. I believe any issues will be within the ESH Automation API, so you may want to followup there, but it makes sense to me to leave this issue open until that is confirmed.
BTW, there is no need to include the Esper module, component script and esper_example.py, unless you are using Esper. These were included in the original repo, and I've considered removing them, but they are good examples. I've also opened #29 to discuss solutions for restructuring the repo for better collaboration.
Thanks for getting back to me. I'll remove everything Esper for the moment.
I'll also see if I can figure out that issue you linked in ESH - a after a quick read I'm not really clear what their issue is, but I'll have a play when I get some more time.
@spacemanspiff2007 is one of the old school JSR223-Jython users... it would be great if we could get him to pop over here too. I've sure he'd appreciate some support on that issue... he brought it up in the forum, and I'd watched the discussion in the Jython repo. I was curious to see how it was going to pan out.
I've been playing around with 2.7.1 but the only problem I encountered was the interpreter isolation issue. Since I am not using esper I did not research further. But my guess that this is the same problem. The interpreter that loads the esper is different since it is a different file so the other file has no access.
Cheers, do you have more info on the isolation issue? I've seen it now with a few other libraries, so understanding more would be a help.
I'm also not using Esper (so have just got rid of the files), and I think a new layout as per #29 would help with that for others moving forwards.
@sillyfrog the jython installer package (http://central.maven.org/maven2/org/python/jython-installer/2.7.0/jython-installer-2.7.0.jar) also includes pip. I haven't used it myself yet, but just so that you know that this isn't exclusive to 2.7.1.
@marcelerkel Unfortunately when I tried the PIP in v2.7.0, it did not go well, and after some searching, I found this is a common problem that's been addressed in v2.7.1. That said, I have not ended up actually using it (yet), because of the interference that from running within openHAB, not really sure why/how, but it was messing with the zlib library (as part of requests). Thanks!
@sillyfrog - have you tried 2.7.1 again? I would like to be able to use pip so that I can use the python requests module.
@mjcumming Here are my notes for getting v2.7.1 going (my plan is to put this on the Wiki when it's enabled): https://gist.github.com/sillyfrog/bc2e8e2546247a616d97078f1e4fa060 However I wanted it for the same reason as you (to install Requests), but it went horribly wrong as it looks like the Java gzip (I think?) module is imported into the same name space, so requests does not work (for my single test case, I have not actually tried very hard as yet to sort this out). But you will at least have a working pip. All of my testing (and production) is done in docker with the v2.4.0 openHAB snapshot (in case it makes a difference). Good luck!
I just ran into a namespace collision using my own code... took forever to figure out what was causing the problem. Many of the modules I am interested in using use requests so will have to figure it out.
Many of the modules I am interested in using use requests so will have to figure it out.
requests
can't be used in Jython... https://community.openhab.org/t/how-to-setup-jython/53049/119?u=5iver
You could use executeCommandLine to run a Python script using requests
directly though.
The link to the python FAQ is for version 2.2. Later documents indicate that you can use cpython modules
Jython 2.7 Beta 2 Released (May 2013) Jython 2.7b2 brings us up to language level compatibility with the 2.7 version of CPython. We have focused largely on CPython compatibility, and so this release of Jython can run more pure Python apps then any previous release. Please see the NEWS file for detailed release notes. This is primarily a bugfix release, with numerous improvements, including much improvement on Windows support. Read more on Frank Wierzbickis Weblog PyDev 3.4.1 Available (May 2013) Please visit the PyDev Site for more information. PyDev 3.0 Released (November 2013) From now on, PyDev requires Eclipse 3.7 or 4.3 onwards and Java 7! For older versions, keep using PyDev 2.x. Interpreter is now kept up to date with changes to the interpreter, so, pip-installing packages will automatically update internal caches without requiring a manual step. Fixed issue connecting to shell for code-completion (which could halt the IDE). Please visit the PyDev Site for more information. JyNI 2.7-alpha 2 Released (October 2013) JyNI is a compatibility layer with the goal to enable Jython to use native CPython extensions like NumPy or SciPy. This way we aim to enable scientific Python code to run on Jython. Since Java is rather present in industry, while Python is more present in science, JyNI is an important step to lower the cost of using scientific code in industrial environments. Our philosophy is to integrate JyNI with Jython and CPython extensions as seamless as possible. So JyNI aims to work without any recompilation of Jython or the desired CPython extensions. It neither requires a customized Jython version, nor customized versions of the CPython extensions (of course your JyNI version must meet the platform your CPython extension was build for). Simply put JyNI.jar on the classpath (
And requests is specifically mentioned here
https://jaxenter.com/java-python-jython-2-7-beta-3-has-arrived-108027.html
I have found that requests, with Jython v2.7.1 works OK (using a GET as a simple test), if it's not part of OpenHAB. However in the openHAB environment things go bad...
For those interested in getting python requests
going it Jython, I have added a note at the end here as to how to make it work :)
https://github.com/OH-Jython-Scripters/openhab2-jython/wiki/Using-PIP-in-Docker
Here a note on Jython 2.7.1. Tried to install the package on my Rasbian PI. I got an installation error on mkdirs (do not have the output): 'File "/opt/jython/Lib/os.py", line 174, in makedirs'. Looks related to http://bugs.jython.org/issue2611. 2.7.0 installed fine. And initial setup went ok for me. Now extend logging... and create sources. ;-)
Not sure if any of you have followed #6392, but I've been running 2.7.1. There have been some errors (detailed in my comment), but I have just updated to 2.7.1.patch2618.jar (I'm using standalone) from https://mvnrepository.com/artifact/org.python/jython-standalone?repo=xebialabs. Hopefully this build will resolve the errors!
This is working, but there is a funky trick to do with ScriptEntensions. I have the scripts and modules updated, but will include this in an upcoming merge to support the ESH migration. Actually, I shouldn't do that. I should merge now and cut a branch, then put the ESH changes in as another release, when the smoke clears.
I've been looking at moving from Jython 2.7.0 to Jython 2.7.1 (as it has built in
pip
- I think - and a number of other bug fixes), and am getting the traceback as per below.I'm happy to look at this further, but not really sure where to start - so if you have any pointers, that would be great.
I found that if I remove the
...automation/lib/python/esper/java/esper-6.1.0.jar
file, things appear to work, except for these errors (which is no surprise):The
hello_world.py
example still works, and is logging every 10 seconds.I'm running things just as outlined in the
Docker.md
file, except with the jython 2.7.1 .bin (from http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar), with the latest snapshot (Build 1392).