Importing snappy fails

Everything with the installations went fine, but importing snappy fails for some reasong. Why?
This is the log from my snaptutil.log:

INFO: Installing from Java module ‘E:\snap\snap\modules\org-esa-snap-snap-python.jar’
INFO: Installing jpy…
INFO: Extracting ‘lib/jpy-0.9.0-cp36-cp36m-win32.whl’ from ‘E:\snap\snap\modules\org-esa-snap-snap-python.jar’
INFO: Unzipping ‘C:\Users\aleks.snap\snap-python\snappy\lib\jpy-0.9.0-cp36-cp36m-win32.whl’
INFO: Configuring jpy…
INFO: jpy Python API configuration written to ‘C:\Users\aleks.snap\snap-python\snappy\jpyconfig.py’
INFO: jpy Java API configuration written to ‘C:\Users\aleks.snap\snap-python\snappy\jpyconfig.properties’
INFO: Configuring snappy…
INFO: snappy configuration written to ‘C:\Users\aleks.snap\snap-python\snappy\snappy.ini’
INFO: Importing snappy for final test…
ERROR: Configuration failed with exit code 30

Please provide more details (SNAP version, OS version, python version). Check that you are not mixing 32-bit and 64-bit versions – jpy-0.9.0-cp36-cp36m-win32.whl is not correct for 64-bit systems.

ERROR: Configuration failed with exit code 30 is very common. A search for that string in the forums may lead you a solution.

I solved it by creating the anaconda environment and execute all of them within this active environment as explained here: https://senbox.atlassian.net/wiki/spaces/SNAP/pages/50855941/Configure+Python+to+use+the+SNAP-Python+snappy+interface
i also followed this instruction to create a different jpy that is compatible with my 64-bit system:
GitHub - bcdev/jpy: A bi-directional Python-Java bridge used to embed Java in CPython or the other way round.

1 Like

Glad you got it working. For the benefit of others who encounter the same problem, it would be helpful to mention the Anaconda version you used.

I downloaded the latest version at that time: 4.10.1

Anaconda 4.10.1 comes in many versions so you should mention the Python version you are actually using (Python 3.6, 3.7, 3.8, and 3.9) are offered (3.6 should not require building jpy).

There are a lot of legitimate questions with regards to the installation fails of the snappy SNAP Python API. I also had a series of issues.

@marpet I don’t want to complain to much because it helped me a lot, but I think the guide Configure Python to use the SNAP-Python (snappy) interface should somehow be at least partly rewritten because it contains some issues.

First, it should specify directly from the beginning that the most recent version of Python are NOT COMPATIBLE.

Secondly, more important, it should at least mention the importance of creating a dedicated environment.

Here-below, I listed the steps that are required to create a python environment dedicated to SNAP.

  1. Install python3.6
sudo apt update
sudo apt upgrade
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.6
sudo apt install libpython3.6-dev

From the Linux manual, the two first commands will re-synchronize the package index files from their sources and install the newest versions of all packages currently installed on the system, and are often used together. The third command will add a new Personal Package Archive (PPA) to our Linux sources. In this case, we are interested in deadsnakes, dedicated to more recent python versions. After resynchronizing the package indexes, we can finally install the python3.6, mandatory to use snappy. We also installed the libpython-dev to extend the python interpreter. Note that some steps might be skippable, depending on your system.

  1. Configure snappy

Using the SNAP installer, launch the command

./esa_snap_xxxxxxxx

with xxxxxxxx the snap version you downloaded.

When asked during the installation, provide the path to the python
executable. This path can be given using the command which python3.6.

  1. Installing Virtualenv
sudo apt install pip
python3.6 -m pip install virtualenv

The first command will install pip, allowing you to install new python libraries. In the second command, we install the virtual environment library.

  1. Create and setup the virtual environment
virtualenv --python=/usr/bin/python3.6 snappy-env
source ~/snappy-env/bin/activate 
python ~/.snap/snap-python/snappy/setup.py install

From the first command, we create a new environment called snappy-env that specifically uses the python3.6. We can enter the virtual environment using the second line. From there, we are in a safe place where we are sure we don’t mess things up and destroy long-established dependencies. The last command add the snappy library in your python environment. From there, snappy can be imported in your python codes. To exit the environment, simply type the command deactivate.

  1. Usage

To test the installation, write python in a terminal and try to import snappy using import snappy. Or directly use

python -c "import snappy"

  1. Installing other libraries

Since you are using a new virgin python version in a dedicated environment, you probably need new libraries, suh as matplotlib, numpy, spectral, and so forth.

python -m pip install numpy matplotlib spectral

I hope it can help.

6 Likes

What happened: I’m trying to install a python module named snappy inside a python environment where dask.distributed is already installed.

Dask Distributed is a generic task manager. You have have posted in a topic marked solved in a forum dedicated to ESA SNAP, a remote sensing package that provides a a python module named snappy, but there are other modules using the “snappy” name, so you need to clarify which “snappy” module you are trying to install.

If you are having problems with ESA SNAP snappy, please read the FAQ (link at top of forum page) and start a new topic. Be sure to give details of you platform and configuration so others with similar environments can comment, and future readers with the same issue can find your topic with a search.