Python subprocess gpt gdal error

Dear developers,

When I run gpt directly from Windows cmd all works fine, but when I do the same from Python with subprocess'gpt -h')

I am getting the following error.

INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
Error: null
	at org.esa.s2tbx.dataio.gdal.GDALLoader.initGDAL(
	at org.esa.lib.gdal.activator.GDALPlugInActivator.start(
	at org.esa.snap.runtime.Engine.informActivators(
	at org.esa.snap.runtime.Engine.lambda$start$0(
	at org.esa.snap.runtime.Engine.runClientCode(
	at org.esa.snap.runtime.Engine.start(
	at org.esa.snap.runtime.Engine.start(
	at org.esa.snap.runtime.Launcher.main(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.exe4j.runtime.LauncherEngine.launch(
	at com.exe4j.runtime.WinLauncher.main(
	at com.install4j.runtime.launcher.WinLauncher.main(
Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 48: C:\Miniconda\envs\plot\Library\bin\gdalinfo.exeC:\Program Files\GDAL\gdalinfo.exe
	at sun.nio.fs.WindowsPathParser.normalize(
	at sun.nio.fs.WindowsPathParser.parse(
	at sun.nio.fs.WindowsPathParser.parse(
	at sun.nio.fs.WindowsPath.parse(
	at sun.nio.fs.WindowsFileSystem.getPath(
	at java.nio.file.Paths.get(
	at org.esa.s2tbx.dataio.gdal.OSCategory.getExecutableLocation(
	at org.esa.s2tbx.dataio.gdal.GDALVersion.retrieveInstalledVersion(
	at org.esa.s2tbx.dataio.gdal.GDALVersion.<clinit>(
	... 16 more

As far as I could read there is something with two gdal version that I have - from osgeo (Miniconda) and system.

I do not think it is SNAP issue but rather Miniconda, but could you give a hint if you have faced it, please.

It says here there is an illegal character “:
Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 48: C:\Miniconda\envs\plot\Library\bin\gdalinfo.exeC:\Program Files\GDAL\gdalinfo.exe

I use Miniconda, Python, and I also call gpt through subprocess. This method works for me.

I think SNAP is confused because somehow you seem to have 2 GDAL installations in your path. How did you install GDAL in your virtual environment?

You can have a look at the option in SNAP Desktop:

Maybe you can use the internal version?
If this doesn’t help, then @oana_hogoiu might be able to help you.

Yes, SNAP cannot handle 2 GDAL versions installed on your system.
You can either decide on one of the installed versions, either use the SNAP internal GDAL version, like @marpet suggested.
Also, maybe it helps to delete SNAP cache (on Windows it’s located under C:\Users[username]\AppData\Roaming\SNAP and on unix it’s under ~/.snap/system)

I don’t know how I got it, in other environment there is only one. I was trying to disable Conda’s gdal but I was not able to find environmental path variables of the virtual environment.
Before the last week it was working fine (SNAP 8).

I tried all the things but it didn’t help.
I agree that this is not SNAP but rather a Conda issue, so I am fine like this.
I changed the environment for this command and all worked fine.
Yet, you might find it interesting to fix, if SNAP asks ‘where gdal’ and expects 1 string, but there are two in my bogus case, which SNAP merges into one and complains about the second “:” in the path, which it the beginning of the second path.
Thank you for you fast reply, anyway.

Hi Prikaziuk,
I’m having the same issue. What exactly did you change in the environment for that command?

So in my case there where 2 instances of gdalinfo.exe: one in my Python environment and one that comes with the SNAP installation. I solved it by renaming the one in the Python environment to “gdalinfo.exe.bak”.

The setting in SNAP Desktop as suggested by @marpet did not help in my case.

Hi scheunro,

An elegant workaround, I just activated another conda environment that worked with conda activate another_env_name.