Help with Snappy instalation

Hello, im new here.
I am using Ubuntu 18.04.4 LTS.
Trying to import the ProductIO function from Snappy but nothing works, always got the same error:
cannot import name 'ProductIO' from 'snappy' (/home/yosdos/miniconda3/lib/python3.7/site-packages/snappy/__init__.py)

i follow the instruction from here including the manually installation but somehow it does not work too. I am getting this:
Python configuration error: Cannot run program "/usr/lib/python3.6" (in directory "/home/yosdos/.snap/snap-python/snappy"): error=13, Permission denied
update:
I succeed to get to this point:
Configuring SNAP-Python interface... Done. The SNAP-Python interface is located in '/home/yosdos/.snap/snap-python/snappy' When using SNAP from Python, either do: sys.path.append('/home/yosdos/.snap/snap-python') or copy the 'snappy' module into your Python's 'site-packages' directory.

but then when i follow the instruction iam getting this:

cannot import name 'ProductIO'

`
Thanks in advance.

You need to provide enough detail so others can reproduce your problem (see How to reports bugs (and problems) effectively. Remember that most forum users aren’t paid to provide help, so you need to make it as easy as possible for someone to understand what you have done.

You appear to be mixing Python versions (python 3.6 as provided by Ubuntu and python 3.7 installed using miniconda3). SNAP doesn’t provide jpy for python 3.7, so unless you have other reasons for using python 3.7 you should stick with the version provided by Ubuntu. Saying you “follow instructions” doesn’t give enough information when the instructions require user-generated input. The message:

Python configuration error: Cannot run program "/usr/lib/python3.6" (in directory "/home/yosdos/.snap/snap-python/snappy"): error=13, Permission denied

would occur if you used /usr/lib/python3.6 (the name of a directory) for <python-exe> (you should use /usr/bin/python3 for Ubuntu 18.04 LTS).

Please show us your version of the command line:

$ ./snappy-conf <python-exe> <snappy-dir>

and also the output of which python python3. I get:

/usr/bin/python
/usr/bin/python3

What did you do following the successful configuration indicated by the Configuring SNAP-Python interface... Done. message? It appears that you copied snappy to the miniconda3 site-packages directory, which would not work without a python 3.7 jpy.

Hey thank you for the fast reply.
i have been trying a lot of configurations, witch mean different types of errors. so ill try to summarize one of them:

After the installation of SNAP software, i installed a new conda environment with Python 3.6
conda create --name myenv python=3.6

and then i got in ~/snap/bin and did this command:
./snappy-conf /home/yosdos/miniconda3/envs/myenv/bin/python3.6

Then something started to run, some java sign appear at my sidebar.
From the same directory i ran the python command:
/home/yosdos/miniconda3/envs/myenv/bin/python3

In python i tried to import ‘ProductIO’ function from snappy:
from snappy import ProductIO

and got this error:
`Traceback (most recent call last):
File “”, line 1, in
ImportError: cannot import name ‘ProductIO’

Thank you!
`

You should not need Anaconda python to use snappy. It only creates more confusion as you have to ensure that the snappy module is installed to the correct location for the version used in the configuration step and then that the same python version is used to run scripts. Have you read the Anaconda environment instructions?

Your python command:

/home/yosdos/miniconda3/envs/myenv/bin/python3

is not correct. You need to run conda activate myenv first. The Anaconda instructions warn: “In general, calling any executable in an environment without first activating that environment will likely not work. For the ability to run executables in activated environments, you may be interested in the conda run command.”

You don’t tell us if you got the message showing a successful result. Note that in some cases the snappy-conf script appears to hang and you have to hit “Enter” to get back to the command prompt.

The snappy instructions specifically say to run the test from <snappy-dir>, which is certainly not ~/snap/bin and is usually ~/.snap/snap-python/snappy.

If the test succeeds, then you need to make the snappy module available to the python version you will be using, and also ensure that you are using the appropriate activation settings with Anaconda Python.

Many users have successfully configured snappy on Ubuntu 18.04 LTS by following the instructions, using Ubuntu’s python 3.6. What happens if you ignore the Anaconda
versions and run:

Please ensure that you don’t have any anaconda environment activated and follow the documented procedure:

$ cd <snap-install-dir>/bin
$ ./snappy-conf <python-exe>

For your system, <python-exe> is /usr/bin/python3.6, so this would be:

$ cd ~/snap/bin
$ ./snappy-conf /usr/bin/python3.6

If this works you should see the same message as the one shown in the documentation, and you can continue to the test and installation sections.

Thank you very much for your help
I forgot to mentioned the obvious, that i launched the myenv environment before the runs. But still, when i follow your instruction:
(base) yosdos@YosDos:~/snap/bin$ ./snappy-conf /usr/bin/python3.6

i am getting this:
Configuring SNAP-Python interface... Done. The SNAP-Python interface is located in '/home/yosdos/.snap/snap-python/snappy' When using SNAP from Python, either do: sys.path.append('/home/yosdos/.snap/snap-python') or copy the 'snappy' module into your Python's 'site-packages' directory.
witch should be fine.

But then (while the last one is running) when i run this command :
(base) yosdos@YosDos:~/.snap/snap-python/snappy$ /usr/bin/python3.6
and import my function in Python:
from snappy import ProductIO

i am getting this error again :
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name 'ProductIO'

Am i missing something?

Thank you again.

Looks good. You have just one small mistake in the test, and then have to deal with configuration. With a fresh install of linux Mint 19 (which is based on Ubuntu 18.04):

$ ./snappy-conf /usr/bin/python3
Configuring SNAP-Python interface...
Done. The SNAP-Python interface is located in '/home/seadas/.snap/snap-python/snappy'

When using SNAP from Python, either do: sys.path.append(’/home/seadas/.snap/snap-python’)
or copy the ‘snappy’ module into your Python’s ‘site-packages’ directory.

Note that <snappy-dir> is ~/.snap/snap-python.

seadas@mint19:~/.snap/snap-python
$ python3
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from snappy import ProductIO
SEVERE: org.esa.s2tbx.dataio.gdal.activator.GDALDistributionInstaller: The environment variable LD_LIBRARY_PATH is not set. It must contain the current folder '.'.
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
INFO: org.esa.snap.core.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience
>>> p = ProductIO.readProduct('snappy/testdata/MER_FRS_L1B_SUBSET.dim')
INFO: org.hsqldb.persist.Logger: dataFileCache open start
>>> list(p.getBandNames())
['radiance_1', 'radiance_2', 'radiance_3', 'radiance_4', 'radiance_5', 'radiance_6', 'radiance_7', 'radiance_8', 'radiance_9', 'radiance_10', 'radiance_11', 'radiance_12', 'radiance_13', 'radiance_14', 'radiance_15', 'l1_flags', 'detector_index']

Don’t worry about the “SEVERE” message.

The final step is to configure Python so it can find the snappy module. There are several ways to do this. I find it better to put the path in my python code (using the USERPROFILE method, but replacing USERPROFILE with HOME on linux) because I work with many other people who use different configurations and want my scripts to work without changes.

Hey
I didn’t get it.
In Python i did this command:
sys.path.append('/home/yosdos/.snap/snap-python')
and i copied the snappy path to the python path and… Nothing!
This is the reason i tried to build a new env to start all over but nothing is seems to work correctly.
thank you again!

You don’t mention if you were able to configure snappy and run the BandNames test. Because the test is run in the snappy folder you shouldn’t need path settings for the test.

It isn’t clear how you used sys.path.append('/home/yosdos/.snap/snap-python'). If the
BandNames test you can use the template below to make a snappy-test.py file that
will run from outside the snappy folder. You can use either python3.6 snappy-test.py
or make snappy-test.py executable and run it like any script or program.

If you copied a non-working snappy folder into the Python tree it may cause problems for a more recent working version of snappy. For Linux MInt 19 or Ubuntu 18.04 LTS, make sure you are running snappy scripts with “/usr/bin/python3.6”.

Once you get the test working, I recommend following the example, but with HOME
replacing USERPROFILE:

#! /usr/bin/python3.6
import os
snappy_envar ='HOME`
envs = os.environ
if not snappy_envar in envs.keys():
    raise Exception('Cannot find snappy')
else:
    snappy_dir = os.path.join(envs.get(snappy_envar), '.snap', 'snap-python')
sys.path.append(snappy_dir)
import snappy 
[.... rest of python code]

OK, Thank you very much!
I gave up, i tried every thing that fit my abilities.
Is there any alternative to this Snappy library ?

It is usually very straightforware to install snappy on Ubuntu 18.04 or Mint 19, so I’m sure there is a simple reason it didn’t work for you. Normally I would suggest getting a more experienced linux user to look at your system, but that may not be possible under social distancing. You will find it useful to study some basic linux concepts. A good starting point is Linux Command. I used to teach practical sessions in ocean remote sensing workshops. We found it best to start a two-week course with a couple afternoons just focusing on linux basic command-line skills.n
If you just jump into complicated software without first getting some basic linux skills you are trying to do too much at once. When approaching a complicated task it is best to work out an approach that uses a series of simple steps. You might start with linux, then work through some SNAP Tutorials for the sort of data and calculations that interest you, and the revisit snappy.

You can write Java apps or plugins that use SNAP’s Java Operators, see SNAP Architecture. There are remote sensing tools in Python, Matlab, R, ArcGIS, IDL, QGIS, and others that don’t use snappy. There are also web sites that provide access to data that has already been processed for particular use cases.

Hi @YosDos if you’re still looking to use snappy, we just recently Dockerised SNAP 7, Python 3.6, and snappy.

You can find it here

Hopefully it will alleviate your installation problems as it’s all containerised :slight_smile:

Fantastic! Does it have GDAL installed as well?

Hi, can you explain what “dockerized” means?

Thank you,

Konrad