As I’m new to SNAP, I have encountered some issues.
I’m trying to access to SNAP process via Python scripts. After reading multiples topics here, snappy seems to be the best solution. Unfortunately, when I try to run the “1st contact” example, there is an error raised: “ImportError: cannot import name ‘ProductIO’ from ‘snappy’ (C:\ProgramData\Anaconda3\lib\site-packages\snappy_init_.py)”.
I tried a lot of different potential solutions without getting anything else. Any idea?
Thank you in advance.
See How to report bugs [and other problems] effectively. You need to tell us which Windows, SNAP, and Python versions you are using, and how you configured snappy.
Please attach the log file generate by snappy-conf.???.
Note that there are multiple Python packages called “snappy”. You seem to be using Anaconda’s snappy compression package. Python has several mechanisms to select from multiple packages with the same name. I find it best to add the appropriate location in each Python script so it is easy to determine which package the script requires.
Thank you for your reply!
I’m indeed using Anaconda 3 on Windows 10. I tried to install both “snappy” and “python-snappy”, and it seems to be okay. I also tried python 3.7.3 on an environment and python 2.7 on another. Finally, SNAP is in the latest version available at the moment, thus 8 if I’m not wrong.
Could you please be more precise about the command snappy-conf? I’m not getting any log file with it.
Also, how to add the appropriate location as mentioned?
As noted in the above document, the most recent supported Python version is 3.6. Either install a python 3.6 environment with conda, or install python 3.6 from python.org. The document mentions several ways to make the SNAP snappy module available to Python. Which one is best for you depends on what other things you may want to do in Python. If you aren’t sure, the third method avoids any possibility of conflicts with other non-ESA “snappy” packages:
import sys
sys.path.append('<snappy-dir>') # or sys.path.insert(1, '<snappy-dir>')
import snappy
I already followed all those steps, but I think there is still a call of the python 3.7 or the snappy in it, even if I configured an environment in 2.7.
Can you tell me more about the log? I was able to find one called “snappy util”. Here it is:
INFO: Installing from Java module 'C:\Users\spyru\AppData\Roaming\SNAP\modules\org-esa-snap-snap-python.jar'
INFO: Installing jpy...
INFO: Extracting 'lib/jpy-0.9.0-cp27-cp27m-win_amd64.whl' from 'C:\Users\spyru\AppData\Roaming\SNAP\modules\org-esa-snap-snap-python.jar'
INFO: Unzipping 'C:\ProgramData\Anaconda3\envs\version27\Lib\site-packages\snappy\snappy\lib\jpy-0.9.0-cp27-cp27m-win_amd64.whl'
INFO: Configuring jpy...
INFO: jpy Python API configuration written to 'C:\ProgramData\Anaconda3\envs\version27\Lib\site-packages\snappy\snappy\jpyconfig.py'
INFO: jpy Java API configuration written to 'C:\ProgramData\Anaconda3\envs\version27\Lib\site-packages\snappy\snappy\jpyconfig.properties'
INFO: Configuring snappy...
INFO: snappy configuration written to 'C:\ProgramData\Anaconda3\envs\version27\Lib\site-packages\snappy\snappy\snappy.ini'
INFO: Importing snappy for final test...
INFO: Done. The SNAP-Python interface is located in 'C:\ProgramData\Anaconda3\envs\version27\Lib\site-packages\snappy\snappy'
When using SNAP from Python, either do: sys.path.append('C:\\ProgramData\\Anaconda3\\envs\\version27\\Lib\\site-packages\\snappy\\snappy')
or copy the snappy module into your Python's 'site-packages' directory.
You need to run scripts that use SNAP snappy with the same Python program used to configure SNAP snappy. It looks like you used the Towards Data Science instructions, which don’t deal with the problem of multiple packages called “snappy” and have outdated information about the Python versions.
It looks like you have a copy of SNAP snappy in Anaconda Python’s 2.7 environment. Normally, SNAP snappy is in %USERPROFILE%\.snap\snap-python\snappy. When you run snappy-conf.bat the log file is created in that directory.
You should note that Python 2.7 is at “end-of-life” and current versions of many important packages are only available for Python 3. If you are new to Python you are generally better
off using 3.6 with SNAP snappy and keeping your installation separate from the conda packages.
Thank you very much for your help!
Actually I realised yesterday what you just explained. So I don’t have errors raised anymore.
If someone having the same issue, I removed both snappy and python-snappy from the site-packages of python 3.7 and 2.7. I uninstalled as well SNAP 8.0.
Then, I followed the steps in the second link of gnwiii (SNAP Python snappy configuration).
What is confusing is that you don’t need to install any packages, only install SNAP and configure it with the python.exe you want to use. Also, the isn’t in site-package but in user.snap\snap-python etc… as gnwiii said in the last post.
There have been changes since this thread began (the instruction now provide a link to instructions for building jpy with a current Python version), but the problem with multiple packages called “snappy” remains. Have you tried the suggestions mentioned in this thread? If those don’t work, you need to
provide enough details to allow others to reproduce the problem.
Yes i looked for many solutions on the internet but i am still facing this issue. I tried reinstalling snap and configure it manually by adding the python executable file in that also .but facing this : cannot import name ‘ProductIO’ from ‘snappy’ (c:\Users\svija\AppData\Local\Programs\Python\Python310\lib\site-packages\snappy_init_.py)
You need to provide more details. You have Python-3.10. Did you build jpy from source using maven or are you using a binary wheel from an site you don’t mentions? What happened when you ran snappy_conf? Are you getting the error when you try to test your installation as described in the official instructions?