9

So, I should not be complaining, but it is annoying. On my setup (Windows Server 2012 R2) importing GDAL in Python in the terminal prints the following:

>>> import gdal
ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
BAG.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
BAG.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
FITS.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
FITS.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
GMT.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
GMT.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF4.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF4.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF4Image.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF4Image.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF5.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF5.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF5Image.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
HDF5Image.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
netCDF.dll
193: %1 is not a valid Win32 application.

ERROR 1: Can't load requested DLL: C:\Program Files (x86)\GDAL\gdalplugins\gdal_
netCDF.dll
193: %1 is not a valid Win32 application.

>>>

But I can still use GDAL without any problems, despite those messages. In Jupyter, those errors are not printed. Per se, I don't care about those messages as long as functionality does not break, and for my usecase, it does not. However, I am calling the function that imports GDAL using multiprocessing Pool, on 12 cores, and it prints that out needlessly 12 times. That gets annoying mainly because it obscures the output I am interested in: execution progress. What can I do about this (either a way to hide these messages, or resolve the underlying issues that cause them to appear)?

Note, Python version is: Python 3.5.1 |Anaconda custom (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v. 1900 64 bit (AMD64)] on win32. GDAL is obviously installed from Anaconda, from the IOOS custom package. GDAL version is 1.11.4, np110py35_vc14_7.

Kartik
  • 8,347
  • 39
  • 73
  • Have you tried using the [logging module to capture warnings](https://docs.python.org/3/library/logging.html#logging.captureWarnings)? Before you import : `import logging; logging.captureWarnings(True); import gdal; logging.captureWarnings(False)`. That might hide them from printing to stderr. – Logan Byers Oct 05 '16 at 23:02
  • I tried everything, right from redirecting the console to using packages to ignore warnings. Although I didn't try your particular solution, I would imagine it won't work. It is not python that is printing the GDAL messages, but GDAL itself. Those warnings are coming from the C code of GDAL, in a way that is not passed through the Python GDAL bindings. So nothing from Python will do the trick, it is a GDAL configuration setting that needs to be changed. I do not know how to do that. – Kartik Oct 05 '16 at 23:26
  • Also, I was an intern at a company where my project involved using GDAL. Since that internship finished, I no longer work with GDAL or have access to the company to try out your solution. But if someone else is using GDAL and has similar issues, that person may benefit from your solution, and may comment to let us know how it works. – Kartik Oct 05 '16 at 23:30

3 Answers3

4

I had a similar issue. I had the GDAL_DRIVER_PATH variable set on Windows, which was causing this logs / errors. I assume it came from a previous installation of GDAL which I made and was still pointing to the wrong directory.

codedge
  • 4,754
  • 2
  • 22
  • 38
DonChulius
  • 63
  • 4
2

Looking at the source, you can see that it tries to import modules in a try/except block. It will print GDAL errors but will not raise Python exceptions, unless that mode is enabled with gdal.UseExceptions().

It is likely that certain functions / functionality would error out but that you are simply not making use of them in your scripts. Specifically, it is looking for some drivers for HDF and other formats. There may have been an issue compiling OSGEO/GDAL since support for some of these formats requires special builds.

You should either re-build correctly if you do need support for these formats, or start again with a fresh "plain" install.

Benjamin
  • 11,560
  • 13
  • 70
  • 119
0

Here is what worked for me: add the gdalplugins folder path (C:\Program Files\GDAL\gdalplugins) to your PATH environment variable.

Tomm
  • 1