Configuration Python to use the SNAP-Python interface (Snappy) within QGIS

I am trying to configure Snnapy to use it within QGIS. To do this I followed these steps:

  1. I configured the Python interpreter in the SNAP installation pointing to the Python interpreter of QGIS:
    “C: \ Program Files \ QGIS 3.10 \ bin \ python3.exe”

  2. From OSGeo4W Shell as System Administrator I did the installation:
    cd “C:\Users\user.snap\snap-python\snappy”
    “C:\Program Files\QGIS 3.10\bin\python3.exe” setup.py install

  3. Copy the /snappy directory directly into the site-packages directory of my Python

  4. Then I tried importing Snnapy from Python and I found the following error:

    import sys
    sys.path.append(‘C:\Program Files\QGIS 3.10\apps\Python37\lib\site-packages\snappy’)
    import snappy
    Traceback (most recent call last):
    File “”, line 1, in
    File “C:\Users\ign\AppData\Local\Programs\Python\Python37\lib\site-packages\snappy_init_.py”, line 62, in
    import jpyutil
    ModuleNotFoundError: No module named 'jpyutil’

Has anyone tried this setup?

The following link indicates that Snappy might not be compatible with Python 3.7

1 Like

At one time, QGIS on Windows included both Python 2.7 and Python 3.7. I was able to configure snappy to use python 2.7, but I never tried using the QGIS python functions. SNAP provides the jpy Python-Java bridge for a only a few Python versions on each platform (Windows, macOS, linux).

The recommended procedure for configuring snappy generates snappyutil.log:

INFO: Installing from Java module 'C:\Users\u\AppData\Roaming\SNAP\modules\org-esa-snap-snap-python.jar'
INFO: Installing jpy...
INFO: Extracting 'lib/jpy-0.9.0-cp36-cp36m-win_amd64.whl' from 'C:\Users\u\AppData\Roaming\SNAP\modules\org-esa-snap-snap-python.jar'
INFO: Unzipping 'C:\Users\u\.snap\snap-python\snappy\lib\jpy-0.9.0-cp36-cp36m-win_amd64.whl'
INFO: Configuring jpy...
INFO: jpy Python API configuration written to 'C:\Users\u\.snap\snap-python\snappy\jpyconfig.py'
INFO: jpy Java API configuration written to 'C:\Users\u\.snap\snap-python\snappy\jpyconfig.properties'
INFO: Configuring snappy...
INFO: snappy configuration written to 'C:\Users\u\.snap\snap-python\snappy\snappy.ini'
INFO: Importing snappy for final test...
INFO: Done. The SNAP-Python interface is located in 'C:\Users\u\.snap\snap-python\snappy'
When using SNAP from Python, either do: sys.path.append('C:\\Users\\u\\.snap\\snap-python\\snappy')
or copy the snappy module into your Python's 'site-packages' directory.

You can check the contents of your ...\modules\org-esa-snap-snap-python.jar to see if newer python versions are supported. It is also possible to build a jpy wheel for other Python versions, but the “official” versions have been widely used so are well-tested in use.

I did so, but I have the following error commented here.

INFO: Installing from Java module 'C:\Program Files\snap\snap\modules\org-esa-snap-snap-python.jar'
INFO: Installing jpy...
ERROR: Traceback (most recent call last):
File ".\snappyutil.py", line 280, in _main
force=args.force)
  File ".\snappyutil.py", line 154, in _configure_snappy
  "  $ cd jpy"
 AttributeError: 'list' object has no attribute 'join'
ERROR: Configuration failed with exit code 40

There was a mistake in the error handling section of snappyutil.py that prevents you from seeing the error message that tells you snappyutil.py didn’t find a matching jpy and suggests downloading the source and building the package.