Installing snappy - jpy problems

Hello,

I have been using the snappy library in Python without any problems until now, on a virtual machine. I have just been given a new desktop computer at work and can now work locally, but am now struggling to install Snappy.

I have setup Python with Anaconda 3, and followed the steps listed below:

  • Installed Java JRE and JDK 8, setup the environement variables
  • Installed SNAP
  • Installed jpy manually, as previously mentionned on this forum
  • Ran ./snappy-conf on my anaconda python path which yielded:

Done. The SNAP-Python interface is located in ‘/home/username/.snap/snap-python/snappy’

  • Ran python setup.py install

When I start a python shell and type: import snappy , I get the following message:

Traceback (most recent call last):
File “”, line 1, in
File “/home/username/.snap/snap-python/snappy/init.py”, line 64, in
import jpy
ImportError: /home/username/.snap/snap-python/snappy/jpy.so: undefined symbol: _Py_ZeroStruct

Does anyone here know how I can sort this out?

Many thanks,

Hi maxlam64,

Which Python version are you running. The missing symbol seems to indicate that it is a 3.5+. Unfortunately, snappy Python bindings are for 3.4 only. We are working on this issue right now.

Regards
Norman

Hi forman,

Thank you for your response. Indeed the problem was linked to the Python version. I have managed to complete the install in a Anaconda Virtual Env, using Python 3.4 .

All the best,

Maxim

Hi Maxim, do you have some tips regarding the snappy installation in the Anaconda virtual environment ? I can’t have a successful install on my secondary py34 environment.

Hello,

I would suggest you take a look at this thread if you haven’t already:

Hi Maxim,

Thanks for the answer.
I’ll have a look and come back with a comment over the solution and resolved issue if it will do the job :).

Hi Maxim,

I tried installing snappy. My conclusion is that you can use snappy only if your start the script from the snappy interface folder. For example I have installed snappy on C:\Users…snappy\snappy-python, if I run the script anywhere on c:\ the script is working, if I move on D:\ then I can’t use snappy and the script is not working. I’m using an anaconda 3 py34 environment.
Do you have any other opinion ?

I didn’t run into this issue (but I’m on Linux). Probably @marpet can help you…

How have you integrated snappy into your anaconda environment?

Which of the steps have you done of the Configure Python
the section on the Configure Python to use the SNAP-Python (snappy) interface page. What kind of error do you get?
I’ve copied the snappy folder into the site-packages directory.
For me, it works also from another drive. See the image.

Hi Marco,

First, thanks for not letting me down :slightly_smiling_face:

Second, I’m resuming in the next rows the steps that I’ve used to enable snappy on Anaconda 3 (x64) .

I installed latest Apache Maven, Visual Studio from Microsoft and latest java client and jdk. Environment variables were configured:
User variables -> Paths
C:\Program Files\apache\maven\bin

System variables
JAVA_HOME -> C:\Program Files\Java\jdk1.8.0_172
JDK_HOME -> JAVA_HOME

Full installed the ESA SNAP software without “Configure SNAP for use with Python” enabled;
Full updates for ESA SNAP;
The installation process created Environment variables -> User variables -> Paths -> C:\Program Files\snap\bin

Full installed Anaconda 3 with Python 3.6

  • In Anaconda prompt I created a new python 3.4 environment.
  • activated python 3.4 new environment in anaconda 3;

While in py34 anaconda activated environment I’ve done the following steps:

  • installing jpy from the C:\Users\The Specialist position by using git clone;
  • from the same position I deployed: ‘snappy-conf C:\Anaconda3\envs\py34\python.exe’;
    cd /snappy;
    python setup.py install

  • copied the C:\Users\The Specialist.snap\snap-python\snappy directory directly into the site-packages directory

  • testing instalation from C:\Users\The Specialist position: python, import snappy -> everything looks great and the my sentinel 2 project is working from this position
  • the importing result looks like the following:

(py34) C:\Users\The Specialist>python
Python 3.4.5 | packaged by conda-forge | (default, Sep 8 2016, 14:36:52) [MSC v.1600 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import snappy
INFO: org.esa.snap.python.gpf.PyOperatorSpi: Python operator ‘py_sambuca_snap_op’ registered (Python module: ‘sambuca_snap_op’, class: ‘sambuca_snap_op’, root: ‘C:\Users\The Specialist\AppData\Roaming\SNAP\modules\org-esa-sen2coral-sen2coral-inversion.jar’)
INFO: org.esa.snap.python.gpf.PyOperatorSpi: Python operator ‘S2RutOp’ registered (Python module: ‘s2_rut’, class: ‘S2RutOp’, root: ‘C:\Users\The Specialist\AppData\Roaming\SNAP\modules\org-esa-snap-snap-rut.jar’)
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters

  • moving to D:\
  • testing snappy
  • python -> import snappy => the module is not loading properly (see the bellow output) and the sentinel 2 script is not working
  • I don’t have sys append or something similar in my script;
    (py34) C:\Users\The Specialist>d:

(py34) D:>python
Python 3.4.5 | packaged by conda-forge | (default, Sep 8 2016, 14:36:52) [MSC v.1600 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import snappy
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters

You can see the difference also in the attached picture.

I don’t understand what should I do more in order to make it work.

Okay, now I see the problem and I can reproduce it.

In general your snappy is working and you could use the API. The problem is that some modules are not loaded. I see the same behaviour when I’m on my drive G. The S2RUT is not loaded in my case.
So it seems that modules installed later or updated are not considered.
I guess somewhere in snappy a wrong path is used. I’ll take look. (SNAP-929)

I’ve found the problem and fixed it. For the explanation see the issue SNAP-929

You can work around the problem by editing the __init__.py of snappy.
Go to method _get_nb_user_modules_dir() line 113.
And change it to:

def _get_nb_user_modules_dir():
    import platform
    from os.path import expanduser

    home_dir = expanduser('~')
    nb_user_dir = None
    if platform.system() == 'Windows':
        if home_dir:
            nb_user_dir = os.path.join(home_dir, 'AppData\\Roaming\\SNAP')
    else:
        if home_dir:
            nb_user_dir = os.path.join(home_dir, '.snap/system')

    if nb_user_dir:
        return os.path.join(nb_user_dir, 'modules')

    return None

Many thanks for the report @geoagr2003

1 Like

I will come back with a feedback tonight! :slight_smile:

I forgot to mention that the reported issue was causing me also the necessity to write folders full paths in order to read/manipulate files from project location because I had to run the project from C:\ … .

Now, I hope to get my project working straight from its location.

Thanks again Marco!

Best regards,
George

Hi Marco,

Just finished in dealing with the proposed solution.

Here are the steps that I pursued in having a clean and correct install of snappy, because there was an already installed version of the module (and I wanted to be sure that everything is ok).

First I uninstalled ESA SNAP, installed back without “Configure SNAP for use with Python” enabled.
2.
Run steps from ‘Configure Python to use the SNAP-Python (snappy) interface’ (https://senbox.atlassian.net/wiki/spaces/SNAP/pages/50855941/Configure+Python+to+use+the+SNAP-Python+snappy+interface) until the step:
Windows:
snappy-conf <python-exe> 3. After the step 2) I have operated the proposed changes inside __init__.py 4. After those changes I tried to permanently install snappy cd /snappy
$ setup.py install
No other folder copy was needed.

Wonderfull, now, the snappy module can be used from any location/disk (see the attached picture). All additionally installed modules are imported. Now I can run my sentinel 2 project from it’s location, no full paths are needed inside the developed modules :slight_smile:

Thanks Marco!

George

1 Like