Installing external modules to jython beta

Tags: #<Tag:0x00007f61700c10b0> #<Tag:0x00007f61700c0f98>

This topic is related to the post [beta testers wanted!] Jython addon w/ helper libraries (requires OH 2.5.x), or more general, the Jython addon w/ helper libraries (requires OH 2.5.x) topic. I have been asked to create a new topic for this.

Problem is how to add a module requests to python scripts ran using the Help Library beta for Jython. This beta is coming with its own jython instance in /etc/openhab2/automation/jython/jython-standalone-2.7.1.jar

After issuing the command proposed

sudo -u openhab pip2 install --ignore-installed --install-option="--prefix=/etc/openhab2/automation/lib/python" requests

the module requests is still not available for Jython scripts. import requests generates an error the module is not available.

Searching for “requests” on top level of my openHABian installation reveals this:

[09:19:32] openhabian@openhab:/$ sudo ls -axld $(sudo find . -name 'requests')
drwxr-xr-x 2 openhabian openhab 4096 May  2 14:58 ./etc/openhab2/automation/lib/jython/requests
drwxr-xr-x 2 openhabian openhab 4096 May  2 14:58 ./srv/openhab2-conf/automation/lib/jython/requests
drwxr-xr-x 2 openhab    openhab 4096 Jun 21 12:35 ./srv/openhab2-userdata/.local/lib/python2.7/site-packages/requests
drwxr-xr-x 2 root       root    4096 May  2 14:51 ./usr/lib/python2.7/dist-packages/requests
drwxr-xr-x 3 root       root    4096 Jul 10  2019 ./usr/lib/python3/dist-packages/requests
drwxr-sr-x 2 root       staff   4096 Dec 30 18:34 ./usr/local/lib/python2.7/dist-packages/requests
drwxr-xr-x 2 openhab    openhab 4096 Jun 21 12:35 ./var/lib/openhab2/.local/lib/python2.7/site-packages/requests

Question: how to install requests for the dedicated jython instance.

Copying automation/lib/jython to automation/lib/python works around the problem, import requests is working afterwards.

Actually, Jython is inside of the addon, somewhere in /var/lib/openhab2/cache/org.eclipse.osgi/ (check your sys.path).

Maybe you had a typo and used jython rather than python? I can’t think of any other explanation for why it would be in the wrong directory. Just move the requests package and its dependencies to /etc/openhab2/automation/lib/python/.

I removed automation/lib/jython and automation/lib/python and re-ran the install command as posted above. requests seems to be installed somewhere (see the other thread on install output), but it is not going to /etc/openhab2/automation/lib/python as expected. Neither is it going to /etc/openhab2/automation/lib/jython

Anyway, I have a working version now and hope for a clean install with OH3.