Esa_snappy: ModuleNotFoundError: No module named 'jpyutil'

I am running the latest version of SNAP on macOS Monterey Version 12.5. I’m using python 3.9.6…

I installed the esa_snappy module during SNAP setup and followed this configuration step:

./snappy-conf <python-exe>

I get an error after running the simple python code:

import esa_snappy
  File "/Users/user/.snap/snap-python/esa_snappy/__init__.py", line 62, in <module>
    import jpyutil
ModuleNotFoundError: No module named 'jpyutil'

After getting this error, I noticed that my esa_snappy folder doesn’t contain any jpyutil file as seen in the following screenshot.

@dolaf can you help?

Hello hassanql,

to investigate your problem, could you please check and provide the following information:

  • the content of the snappyutil.log file in your esa_snappy folder

  • the content of the corresponding SNAP log file ‘messages.log’ which should be located in your [home directory]/.snap/system/var/log folder

  • the output returned from your Python with the commands

    >>> import distutils.util
    >>> print (distutils.util.get_platform())
    

Thanks a lot,
Olaf

Hello dolaf,

thank you for your quick reply. Your answers in previous threads were very useful to me. I was able to find a workaround for the issue in the post and now the basic test code is working as follows.

import os

# Set the environment variables
os.environ['JAVA_HOME'] = '/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home'
os.environ['SNAP_HOME'] = '/Applications/esa-snap'

# Verifying the variables
print("JAVA_HOME:", os.environ.get('JAVA_HOME'))
print("SNAP_HOME:", os.environ.get('SNAP_HOME'))

import sys
sys.path.append('/Users/User/.snap/snap-python')  # esa_snappy directory

from esa_snappy import ProductIO,GPF
p = ProductIO.readProduct('/Users/User/.snap/snap-python/esa_snappy/testdata/MER_FRS_L1B_SUBSET.dim')
print(list(p.getBandNames()))

Output:

JAVA_HOME: /Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home
SNAP_HOME: /Applications/esa-snap
['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']

However, now I am encountering a different issue that I will post on another reply.

Here is the information that you asked for:

  • I attached the log file for your reference
    snappyutil.log (843 Bytes)

  • I attached the log file for your referencemessages.log (62.3 KB)

  • Here is the output: macosx-10.9-universal2

Title : GDALProductReader Error

After verifying I can import esa_snappy, I wanted to write a basic script that converts .tiff file to .png.
Here is the code that I tried:

# Path to .tiff file
tiff_file = '/Users/PATHTOFILE/S1A_IW_GRDH_1SDV_20240822T032941_20240822T033015_055320_06BECC_2CDD_COG.SAFE/measurement/s1a-iw-grd-vv-20240822t032941-20240822t033015-055320-06becc-001-cog.tiff'

# Load the .tiff file as a product using esa_snappy
product = ProductIO.readProduct(tiff_file)

Output:

RuntimeError                              Traceback (most recent call last)
Cell In[160], line 8
      5 tiff_file = '/Users/PATHTOFILE/TASK_1/S1A_IW_GRDH_1SDV_20240822T032941_20240822T033015_055320_06BECC_2CDD_COG.SAFE/measurement/s1a-iw-grd-vv-20240822t032941-20240822t033015-055320-06becc-001-cog.tiff'
      7 # Load the .tiff file as a product using esa_snappy
----> 8 product = ProductIO.readProduct(tiff_file)

RuntimeError: java.lang.NoClassDefFoundError: Could not initialize class org.esa.snap.dataio.gdal.reader.GDALProductReader

I also tried verifying that I can view .tiff files on the SNAP software but the software didn’t allow me. I’d be grateful if you can assist me with this.

Hello Hassan,

good to hear that you could solve your original problem with the hints which were given in this forum.

However, your new problem does not seem to be related to esa_snappy. As you say that you cannot even open that tif file with SNAP desktop, it sounds like a problem in the SNAP core modules. Thus I suggest that you also report the issue in the more general part of the forum, e.g. here. Apart from that I’ll ask colleagues if they might know about the problem.

Cheers,
Olaf

1 Like

Hello Hassan,

Can you check if the /Users/User/.snap/auxdata directory contains a gdal folder and a gdal.lock file, delete them and run your script again?

Hello Diana,

I located the GDAL folder in the directory you mentioned, and after deleting it, I was able to successfully view the TIFF file using the SNAP software. However, I noticed that the GDAL folder reappears after running SNAP.Here arethe contents of the gdal folder for your reference


Despite this, when I attempt to run my code, I’m still encountering the same error as before.

Do you have any further suggestions on how I can resolve this issue?
Here is my terminal configuration for your reference:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Ho$
export SNAP_HOME=/Applications/esa-snap
export GDAL_DATA="/opt/homebrew/share/gdal"
export GDAL_LIBRARY_PATH="/opt/homebrew/lib"
export DYLD_LIBRARY_PATH="/opt/homebrew/lib"
export PYTHONPATH="/Users/User/Library/Python/3.9/lib/python/site-packages:$PY$
export JAVA_OPTS="-Djava.library.path=/opt/homebrew/lib"
export PATH="/opt/homebrew/bin:$PATH"

Thank you for your help!

The gdal folder is recreated by SNAP if it does not exist. Sometimes it can happen that its content becomes corrupted, and for this reason, it needs to be deleted.

If I understood correctly, you are able to open TIFF files with SNAP, but not from your python script.

Could you remove these to lines and try again?
export GDAL_DATA=“/opt/homebrew/share/gdal”
export GDAL_LIBRARY_PATH=“/opt/homebrew/lib”

Yes. You are right.

I removed the lines but still getting the same error.