Error using GPT with subprocess


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)

the call is simply:[‘gpt’, ‘/path/to/myGraphTest.xml’,
…: “-Pinput={}”.format(input),
…: “-Poutput={}”.format(output)])

I cannot understand what can be the problem. Do you have any suggestion?

Thank you,

What version os SNAP are you using? My absent-minded scientist’s brain thinks this message was converted to a warning in current SNAP versions.

Are you running Python from the same andra user? Recent linux distros generally set permissions that don’t allow access to other users’ files.

What do you get (using a terminal) for ls -l /home/andrea/PyCharmProjects/MLTest/RUS/myGraphTest.xml ?

This fragment suffers from some editor’s “smart quotes” (this can be hard to see on a laptop screen).

In a python session you could try:

import subprocess['ls', '-l', '/home/andrea/PyCharmProjects/MLTest/RUS/myGraphTest.xml')

You should see the ls -l output and

CompletedProcess(args=['ls', '-l', '/home/andrea/PyCharmProjects/MLTest/RUS/myGraphTest.xml'], returncode=0)

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 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).