AttributeError: module 'snappy' has no attribute 'ProductIO'

Hello there. As I mentioned in the title, when I try to use the ProductIO option on the jupyter notebook, I get this error. Things I’ve tried so far:

  • I downloaded the python-snappy package not snappy
  • I deleted other python versions and downloaded 3.6.
  • I opened a new environment in Anaconda with python 3.6 and uploaded my packages to it.
  • Try to import the package as from snappy import ProductIO

Also I can import snappy itself without getting error:
Ekran Alıntısı

But when I call the ProductIO it gives me an error:
Ekran Alıntısı

OS: Windows 10
Python version: Python 3.6.0
Conda version: conda 4.12.0

Appreciate any suggestion…

This morning I read another topic about this issue https://forum.step.esa.int/t/productio-import-error-using-snappy/ and then I tried to snappy-conf command to make the bridge with my environment. The error code is this:

There are multiple Python packages called “snappy”. ESA SNAP snappy is included with ESA SNAP and the installer gives you the option to configure it at install time, or later by running snappy_conf.

Chances are that a random :python-snappy" package is not ESA SNAP snappy.
Even if you successfully run snappy_conf, python import may use a different package. If find the most reliable way to ensure that you import ESA SNAP snappy
is to use:

import sys
sys.path.insert(0, "<path of ESA SNAP snappy>")

at the start of your python scripts.

Please follow the official instructions for configuring ESA snap snappy.

You also note that providing the path to python in an anaconda environment does not fully enable the environment so gives “undefined behavior (up to and including damage to your system!)”. If you are using python 3.6 from an anaconda environment you should activate the environment before running snappy_conf.

Note that you should not need an admin terminal to manage ESA SNAP on Windows. In general, elevated privileges should only be used for Windows administration. End-user apps generally can be managed using the user’s privileges.

Dear gnwiii,
Thank you for your brief explanation. I remove SNAP and install it again. I tried to make configuration operation during the installation by simply giving the path “C:\Users\gulni\AppData\Local\Programs\Python\Python36”. And then I tried the snappy-conf operation again:

But no luck. Now it says no module named ‘jpy’

Also I didn’t get what do you mean by saying this. Did I need to make the whole snappy-conf operation in Anaconda Powershell command prompt?

It looks like you are very close to success.

The screen capture appears to match the one shown in the official instructions. What happens at the next step where you try to import snappy?

The no module named 'jpy' error occurs if you try to use snappy with a different version of python than the one you used to configure ESA SNAP snappy.

If you configure snappy using an Anaconda environment, you need to run it with the same Anaconda environment. I have an Anaconda Powershell command prompt, but with Python 3.10. This system has a “snappy” environment with Python 3.8:

(base) PS C:\Users\g> cd .\.snap\snap-python\
(base) PS C:\Users\g\.snap\snap-python> python --version
Python 3.10.4
(base) PS C:\Users\g\.snap\snap-python> python -c "import snappy"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\g\.snap\snap-python\snappy\__init__.py", line 65, in <module>
    import jpy
ImportError: DLL load failed while importing jpy: The specified module could not be found.
(base) PS C:\Users\g\.snap\snap-python> conda activate snappy
(snappy) PS C:\Users\g\.snap\snap-python> python -c "import snappy"
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: GDAL not found on system. Internal GDAL 3.0.0 from distribution will be used. (f1)
INFO: org.esa.s2tbx.dataio.gdal.GDALVersion: Internal GDAL 3.0.0 set to be used by SNAP.
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.

After I apply your suggestions, I tried to import snappy in new python 3 notebook it works. I can import snappy but now I can’t import other packages that I want to use with snappy.

from osgeo import gdal
from PIL import Image
import numpy as np
import matplotlib as mtp
import matplotlib.pyplot as plt
import pandas as pd
import geopandas as gpd
import earthpy.plot as ep
import rasterio
from rasterio.plot import reshape_as_raster, reshape_as_image

%matplotlib inline

pd.options.display.max_colwidth = 89

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\anaconda3\envs\class_env7\lib\site-packages\osgeo\__init__.py in swig_import_helper()
     17         try:
---> 18             return importlib.import_module(mname)
     19         except ImportError as e:

~\anaconda3\envs\class_env7\lib\importlib\__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

~\anaconda3\envs\class_env7\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

~\anaconda3\envs\class_env7\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

~\anaconda3\envs\class_env7\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

~\anaconda3\envs\class_env7\lib\importlib\_bootstrap.py in _load_unlocked(spec)

~\anaconda3\envs\class_env7\lib\importlib\_bootstrap.py in module_from_spec(spec)

~\anaconda3\envs\class_env7\lib\importlib\_bootstrap_external.py in create_module(self, spec)

~\anaconda3\envs\class_env7\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

ImportError: DLL load failed: Belirtilen yordam bulunamadı.

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-f83b0c72ef6e> in <module>
----> 1 from osgeo import gdal
      2 from PIL import Image
      3 import numpy as np
      4 import matplotlib as mtp
      5 import matplotlib.pyplot as plt

~\anaconda3\envs\class_env7\lib\site-packages\osgeo\__init__.py in <module>
     30                     raise ImportError(traceback_string + '\n' + msg)
     31             return importlib.import_module('_gdal')
---> 32     _gdal = swig_import_helper()
     33     del swig_import_helper
     34 elif version_info >= (2, 6, 0):

~\anaconda3\envs\class_env7\lib\site-packages\osgeo\__init__.py in swig_import_helper()
     29                     traceback_string = ''.join(traceback.format_exception(*sys.exc_info()))
     30                     raise ImportError(traceback_string + '\n' + msg)
---> 31             return importlib.import_module('_gdal')
     32     _gdal = swig_import_helper()
     33     del swig_import_helper

~\anaconda3\envs\class_env7\lib\importlib\__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

ModuleNotFoundError: No module named '_gdal'

Glad you got snappy working. If you are using a fresh installation of Python, it won’t have the packages installed earlier on different versions of Python, Anaconda does not share packages with other Python packages (e.g., python.org), so you will need to install the missing packages in the Anaconda environment that provides ESA SNAP snappy using conda.