Skip to content

Instantly share code, notes, and snippets.

@Manouchehri
Forked from sillyfrog/pip.md
Created July 27, 2023 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manouchehri/b49c0f46cd5ebb24c88270a3ce0d6be4 to your computer and use it in GitHub Desktop.
Save Manouchehri/b49c0f46cd5ebb24c88270a3ce0d6be4 to your computer and use it in GitHub Desktop.
pip in Jython

To use pip, you must be running Jython v2.7.1 (downloaded from here: http://search.maven.org/remotecontent?filepath=org/python/jython-standalone/2.7.1/jython-standalone-2.7.1.jar). This is not compatible with Esper, so be sure to remove all of these files before upgrading, ie:

rm -rf ./automation/jsr223/000_components/000_Esper.py ./automation/lib/python/esper

With v2.7.1 installed, we can run the Jython from the openHAB installation to install pip

java -jar /openhab/conf/automation/jython/jython-standalone-2.7.1.jar -m ensurepip

Important: Do not upgrade pip, v18.1 in Jython/openHAB appears to have issues with some packages, v9.0.1 continues to work OK.

Ignore errors such as:

  Failed to open /openhab/conf/automation/jython/bin/jython

This is pip/Python trying to run jython as a shell application, which as it's running in Java won't work (there's probably an easy solution using a wrapper script, but as the only goal is to install packages, I have not done any work to make this happen)

You can then install any (pure Python) packages you want, for example, to install Requests:

java -jar /openhab/conf/automation/jython/jython-standalone-2.7.1.jar -m pip install requests

Note: you may have to restart openHAB to get access to the new libraries as the module cache is not reloaded. If nothing has attempted to import the module, it should just work with a reload of the script, however a full restart of the openHAB container is safest to ensure it's pulling all of the new modules in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment