I want to use GPT through subprocess in python to batch run a graph saved in a xml.
To test functionality the graph is just an IO reader: it reads a Sentinel 1 product and saves it as GeoTiff. Here it is the graph file: myGraphTest.xml (754 Bytes)
If I run the graph using command line it works perfectly however when I run it using subprocess I receive the following message:
INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
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.util.EngineVersionCheckActivator: Please check regularly for new updates for the best SNAP experience.
Error: /home/andrea/PyCharmProjects/MLTest/RUS/myGraphTest.xml (No such file or directory)
Thank you - it was a permission issue on the GPT file (root file, with only x permissions to other users). I did not think about it as it was working on command line under the same user.
Anyway, I solved with:
chmod 777 /opt/snap/bin/gpt
I am using SNAP 7.0 however that SEVERE warning is not causing any issue
It doesn’t make sense that gpt was working from the command line but not using python subprocess.run(). Do you have more than one SNAP installation?
Before changing permissions you should examine ownership with ls -l /opt/snap/bin/gpt. It is helpful to mention the linux distro as there are different security models (SELinux versus AppArmor).
chmod 777 is not a solution, as it gives everyone write access to gpt. We can’t know how the permission problem occurred, but such problems are often followed by other problems using snap.
If you are the only user of the system, you can reinstall snap after changing the ownership of /opt/snap to your login (e.g., sudo chown -R <your_login>:<your_group> /opt/snap). Systems with multiple users use many different configurations depending on how they are being used (e.g., each user has different projects versus a rotating group of users working on one project).