Skip to content

pygmt.show_versions doesn't show GDAL version #4102

Closed

Description

@seisman
>>> import pygmt
>>> pygmt.show_versions()
PyGMT information:
  version: v0.17.0.dev11+g0c57126f35
System information:
  python: 3.13.5 | packaged by conda-forge | (main, Jun 16 2025, 08:23:50) [Clang 18.1.8 ]
  executable: /opt/miniforge/envs/pygmt/bin/python3.13
  machine: macOS-14.6.1-x86_64-i386-64bit-Mach-O
Dependency information:
  numpy: 2.3.0
  pandas: 2.3.0
  xarray: 2025.6.1
  packaging: 25.0
  contextily: 1.6.2
  geopandas: 1.1.0
  IPython: 9.3.0
  pyarrow: 20.0.0
  rioxarray: 0.19.0
  gdal: None
  ghostscript: 10.04.0
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: /opt/miniforge/envs/pygmt/share/gmt
  plugin dir: /opt/miniforge/envs/pygmt/lib/gmt/plugins
  library path: /opt/miniforge/envs/pygmt/lib/libgmt.dylib
  cores: 8
  grid layout: rows
  image layout:
  binary version: 6.5.0

Currently, we use the importlib library to obtain the GDAL version, but this only works when the GDAL Python bindings are installed.

Six months ago, we updated GMT's dependency from gdal to libgdal-core (see conda-forge/gmt-feedstock@48fb3f0), so now only the GDAL C library is included, without the Python bindings. This explains why importlib fails.

Potential solutions:

  1. Use subprocess to call gdalinfo --version and parse the output
  2. Use ctypes to obtain the GDAL version directly from the C library
  3. No longer query the GDAL version

I have no strong preferences. Which one do you prefer? Or do you have a better solution?

Activity

  1. added
    maintenance
    on Sep 18, 2025
  2. weiji14 commented on Sep 19, 2025

    @weiji14
    Member

    For reference, rioxarray.show_versions gets its GDAL version using this chunk of code - https://github.com/corteva/rioxarray/blob/5cc63a7dc66535d427ec510da695eace48e5b840/rioxarray/_show_versions.py#L38-L52

    We could probably do a similar try-except. Try to parse the GDAL version from rasterio/rioxarray (if installed), otherwise fallback to using a subprocess call? Ideally we could get it from GMT somehow if there is a C API that exposes it.

  3. seisman commented on Sep 19, 2025

    @seisman
    MemberAuthor

    In #4104, ctypes is used to get the GDAL version from the GDAL C library.

  4. added this to the 0.17.0 milestone on Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions