Installing Snappy (SNAP toolbox python bindings) on Ubuntu 22.10 (kinetic)

Posted on Fr 12 Mai 2023 in misc

  • Download SNAP package and install it:
    • chmod +x esa-snap_sentinel_unix_9_0_0.sh
    • ./esa-snap_sentinel_unix_9_0_0.sh
    • Installation directory: ~/.snap
    • Symlink folder: ~/.local/bin ("Select the folder where you would like ESA SNAP to create symlinks, then click Next.")
    • Python path: /usr/bin/python3 ("Python executable")
  • Install OpenJDK 8:
    • as documented on the ubuntuusers.de wiki: sudo apt install openjdk-8-jre openjdk-8-jdk openjdk-8-demo openjdk-8-doc openjdk-8-jre-headless openjdk-8-source
  • Either:
    • Build python-java bridge jpy manually and then notice, that it fails later on with RuntimeError: jpy: internal error: static method not found: unwrapProxy(Ljava/lang/Object;)Lorg/jpy/PyObject;
    • https://github.com/jpy-consortium/jpy
    • Install requirement for building sudo apt install maven
    • set correct paths, in my case: export JDK_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/; export JAVA_HOME=$JDK_HOME
    • Build it: python3 setup.py build maven bdist_wheel
    • and find it under dist/
  • or use jpy from anaconda, which is recommended in one thread in the ESA forum
    • Download: wget https://anaconda.org/Terradue/jpy/0.9.0/download/linux-64/jpy-0.9.0-py38_3.tar.bz2
    • unpack it, and find the file jpy-0.9.0-cp38-cp38-linux_x86_64.whl
  • Install python3.8, as the current python 3.10 seems to be incompatible:
    • add repository sudo add-apt-repository ppa:deadsnakes/ppa
    • modify /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-kinetic.list and replace the word kinetic (the current version 22.10) with jammy (the LTS version 22.04). It should then read deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ jammy main
    • Get the package list and install it: sudo apt update && sudo apt install python3.8 python3.8-tk python3.8-distutils python3.8-venv
  • create a new virtual environment:
    • create it: python3.8 -m venv snappy-env38
    • activate it: source snappy-env38/bin/activate
  • Configure snappy for this environment:
    • Run ./.snap/bin/snappy-conf $(command -v python3.8) for a first time, this fails in the end but creates some required folders.
    • Copy the jpy wheel downloaded from anaconda into the snappy directory: cp snappy-installation/jpy_wheel/jpy-0.9.0-cp38-cp38-linux_x86_64.whl .snappy/snappy/
    • Run the configuration tool again: ./.snap/bin/snappy-conf $(command -v python3.8), this should work now. Maybe it hangs with Done. The SNAP-Python interface is located in '/home/trossberg/.snappy/snappy' When using SNAP from Python, either do: sys.path.append('/home/trossberg/.snappy') or copy the 'snappy' module into your Python's 'site-packages' directory. This can be ignored and the programm stopped.
    • Install snappy in the environment python3.8 .snappy/snappy/setup.py install
  • Test it: python3.8 -c "import snappy"