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

subprocess.call('gpt -h')

I am getting the following error.

INFO: org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO: Initializing external tool adapters
Error: null
java.lang.ExceptionInInitializerError
	at org.esa.s2tbx.dataio.gdal.GDALLoader.initGDAL(GDALLoader.java:54)
	at org.esa.lib.gdal.activator.GDALPlugInActivator.start(GDALPlugInActivator.java:22)
	at org.esa.snap.runtime.Engine.informActivators(Engine.java:222)
	at org.esa.snap.runtime.Engine.lambda$start$0(Engine.java:121)
	at org.esa.snap.runtime.Engine.runClientCode(Engine.java:189)
	at org.esa.snap.runtime.Engine.start(Engine.java:121)
	at org.esa.snap.runtime.Engine.start(Engine.java:90)
	at org.esa.snap.runtime.Launcher.run(Launcher.java:51)
	at org.esa.snap.runtime.Launcher.main(Launcher.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:84)
	at com.exe4j.runtime.WinLauncher.main(WinLauncher.java:94)
	at com.install4j.runtime.launcher.WinLauncher.main(WinLauncher.java:25)
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(WindowsPathParser.java:182)
	at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
	at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
	at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
	at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
	at java.nio.file.Paths.get(Paths.java:84)
	at org.esa.s2tbx.dataio.gdal.OSCategory.getExecutableLocation(OSCategory.java:120)
	at org.esa.s2tbx.dataio.gdal.GDALVersion.retrieveInstalledVersion(GDALVersion.java:166)
	at org.esa.s2tbx.dataio.gdal.GDALVersion.<clinit>(GDALVersion.java:50)
	... 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.