Skip to main content

GDAL/OGR in Python

This Python package and extensions are a number of tools for programming and manipulating the GDAL Geospatial Data Abstraction Library. Generally speaking the classes and methods mostly match those of the GDAL and OGR C++ classes.

A basic starting point is the Vector API Tutorial. For full documentation, see the GDAL Python API.

The GDAL Python package is built using SWIG. The GDAL project maintains these Python bindings for GDAL/OGR within the gdal source tree. The SWIG-generated files are not checked in and are not part of the gdal release tarballs. The bindings are also made available via PyPi where the swig-generated files are provided.

Building from source

To build from source, there are multiple possible paths.

Dependencies

(As usual, when a package is listed one needs the parts used to build programs against it, called -devel on many systems. This is not special about gdal.)

  • SWIG (4 or greater).

  • libgdal (3.12.4 or greater).

  • numpy (1.0.0 or greater). This is not force-required by the build, but many examples and utilities will not work without it. At least osgeo.gdal_array requires numpy at build time; building without numpy and installing it later does not result in correct operation. apparently not and in any case it is an unwarranted leap.

  • setuptools (python)

  • wheel (python)

Building when building the rest of GDAL

Python bindings are generated by default when building GDAL from source. For more detail, see Python bindings options

Building just the bindings, from the full tree

Another is to use the gdal source distribution with an already-installed gdal library and headers. To do this, one must create a build directory and run cmake to generate build scripts. Then, run cmake --build . --target python_generated_files. Finally, in swig/python, one can build using setup.py like any other distributed python module.

Building from the PyPi module file

The third is to obtain the PyPi-hosted module file, within which swig has been run; this saves running cmake and generating bindings. See HOWTO-RELEASE for how this is created. Because swig has been run, it need not be installed.

Installation via packaging systems

General

Many packaging systems (on GNU/Linux, various BSDs) provide the bindings as a package. Specific instruction are given in cases when that hint might not be sufficient.

pip

Due to the complex nature of GDAL and its components, different bindings may require additional packages and installation steps. GDAL can be installed from the Python Package Index:

pip install gdal

In order to enable numpy-based raster support, libgdal and its development headers must be installed as well as the Python packages numpy, setuptools, and wheel. To install the Python dependencies and build numpy-based raster support:

pip install numpy>1.0.0 wheel setuptools>=67
pip install gdal[numpy]=="$(gdal-config --version).*"

Users can verify that numpy-based raster support has been installed with:

python3 -c 'from osgeo import gdal_array'

If this command raises an ImportError, numpy-based raster support has not been properly installed:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.12/dist-packages/osgeo/gdal_array.py", line 10, in <module>
  from . import _gdal_array
ImportError: cannot import name '_gdal_array' from 'osgeo' (/usr/local/lib/python3.12/dist-packages/osgeo/__init__.py)

This is most often due to pip reusing a cached GDAL installation. Verify that the necessary dependencies have been installed and then run the following to force a clean build:

pip install --no-cache --force-reinstall gdal[numpy]=="$(gdal-config --version).*"

Potential issues with GDAL >= 3.9, Python >= 3.9 and NumPy 2.0 (pip)

The pyproject.toml file of GDAL 3.9 requires numpy >= 2.0.0rc1 (for Python >= 3.9) at build time to be able to build bindings that are compatible of both NumPy 1 and NumPy 2. If for some reason the numpy >= 2.0.0rc1 build dependency can not be installed, it is possible to manually install the build requirements, and invoke pip install with the --no-build-isolation flag.

pip install numpy==<required_version> wheel setuptools>=67
pip install gdal[numpy]=="$(gdal-config --version).*" --no-build-isolation

Conda

GDAL can be quite complex to build and install, particularly on Windows and MacOS. Pre built binaries are provided for the conda system:

https://docs.conda.io/

By the conda-forge project:

https://conda-forge.org/

Once you have Anaconda or Miniconda installed, you should be able to install GDAL with:

conda install -c conda-forge gdal

Usage

Imports

There are five major modules that are included with the GDAL Python bindings.:

>>> from osgeo import gdal
>>> from osgeo import ogr
>>> from osgeo import osr
>>> from osgeo import gdal_array
>>> from osgeo import gdalconst

API

Numpy

One advanced feature of the GDAL Python bindings not found in the other language bindings is integration with the Python numerical array facilities. The gdal.Dataset.ReadAsArray() method can be used to read raster data as numerical arrays, ready to use with the Python numerical array capabilities.

Tutorials

Gotchas

Although GDAL’s and OGR’s Python bindings provide a fairly “Pythonic” wrapper around the underlying C++ code, there are several ways in which the Python bindings differ from typical Python libraries. These differences can catch Python programmers by surprise and lead to unexpected results. These differences result from the complexity of developing a large, long-lived library while continuing to maintain backward compatibility. They are being addressed over time, but until they are all gone, please review this list of gotchas.

Examples

Performance Notes

  • ReadAsArray expects to make an entire copy of a raster band or dataset unless the data are explicitly subsetted as part of the function call. For large data, this approach is expected to be prohibitively memory intensive.

Metadata

Release files for gdal-wheel 3.12.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for gdal-wheel 3.12.4
File
gdal_wheel-3.12.4-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
gdal_wheel-3.12.4-cp314-cp314t-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64 Details
gdal_wheel-3.12.4-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
gdal_wheel-3.12.4-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
gdal_wheel-3.12.4-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details
gdal_wheel-3.12.4-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details
gdal_wheel-3.12.4-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
gdal_wheel-3.12.4-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
gdal_wheel-3.12.4-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
gdal_wheel-3.12.4-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
gdal_wheel-3.12.4-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
gdal_wheel-3.12.4-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 263.0 MB

Release files / gdal_wheel-3.12.4-cp314-cp314t-win_amd64.whl

Download URL gdal_wheel-3.12.4-cp314-cp314t-win_amd64.whl
Size 19.2 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
52703351847072bedae5de96c51a8ebdf272b2ee1c15f2aadbba386024d9982e
BLAKE2b-256 checksum
How to use checksums
b6f2ab7b0715bc01e3e18b8b055ccac031f7e0ba070b9bf09d20de272457c21f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp314-cp314t-manylinux_2_28_x86_64.whl

Download URL gdal_wheel-3.12.4-cp314-cp314t-manylinux_2_28_x86_64.whl
Size 28.0 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ba96e2633279ff8d0bc6578c7ea3b57070135df590f1a2c3198f8eaf69befe28
BLAKE2b-256 checksum
How to use checksums
a344c0b796467cfc9568e84e36f932c188fff9d37ecea53673316a0abcb517d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp314-cp314t-macosx_11_0_arm64.whl

Download URL gdal_wheel-3.12.4-cp314-cp314t-macosx_11_0_arm64.whl
Size 18.8 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6f193c5369c562b5b28ab86bf118051f196cef72d8383c29bce1deceeca1fd71
BLAKE2b-256 checksum
How to use checksums
7ef784f67425a88a77e92eab6f8e0bf820e685d968a7fff88733278f507643da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp314-cp314-win_amd64.whl

Download URL gdal_wheel-3.12.4-cp314-cp314-win_amd64.whl
Size 19.1 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
37c559e09bffbb1533ff128fdd9acdc6da0c09a2eb6fdc0371be3933fda3cbe5
BLAKE2b-256 checksum
How to use checksums
29d6670ccea6fe1d5923573abc49248bfddace23485870080fdc83189421eb83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL gdal_wheel-3.12.4-cp314-cp314-manylinux_2_28_x86_64.whl
Size 28.1 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e23b46f0a6853ef66fc52be2753925569af0444694d27db6e839d56115f1b67a
BLAKE2b-256 checksum
How to use checksums
fad688ce13ec9f0c91af35df5b6bb8747d8ef1c30539e02494b07c4c2a80b991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp314-cp314-macosx_11_0_arm64.whl

Download URL gdal_wheel-3.12.4-cp314-cp314-macosx_11_0_arm64.whl
Size 18.8 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8b45f76f7ecb9ccb54780fc300f24f798d88758a25859724ebb2300761ad121e
BLAKE2b-256 checksum
How to use checksums
f1d742c4dbc912c977077aee27e947d947a35b2b13494385da0660208409148a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp313-cp313-win_amd64.whl

Download URL gdal_wheel-3.12.4-cp313-cp313-win_amd64.whl
Size 18.5 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
c19838dd62a64b7ff49e9853ce410e55bbc46e4bd546c219576ddb8fe7b32bcc
BLAKE2b-256 checksum
How to use checksums
a61e1befb8219e106d68a150c10dfff0a70d44eef5470609b4ecfd558e0429c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL gdal_wheel-3.12.4-cp313-cp313-manylinux_2_28_x86_64.whl
Size 28.1 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
be4afba5f32754390cfec4af52e2ead8b7f45882a07f3ad4ee3627f4e2800c71
BLAKE2b-256 checksum
How to use checksums
62ccd0383666197778663534c624fb030450ee5d4d7d014578056cf2b1c52651
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp313-cp313-macosx_11_0_arm64.whl

Download URL gdal_wheel-3.12.4-cp313-cp313-macosx_11_0_arm64.whl
Size 18.8 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
96cfa1c74b3a1a84987f8bd378d14eed684c529fb1dd3e6898035fc334094ed0
BLAKE2b-256 checksum
How to use checksums
d90c082a50311487d23fa707366f3185dd3bc7cd22ddb95f0456f711ca7e379f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp312-cp312-win_amd64.whl

Download URL gdal_wheel-3.12.4-cp312-cp312-win_amd64.whl
Size 18.5 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
58fd1b2e5ea8d440dacaa4b544d7905609f331ac2b66817cf2af21730ea47907
BLAKE2b-256 checksum
How to use checksums
b75aadb78d9f9373fbeb22c08311ba81760ff3c106bd4d95064d7d3a876ca2d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL gdal_wheel-3.12.4-cp312-cp312-manylinux_2_28_x86_64.whl
Size 28.1 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
6eb16fcf85dd2a909e7820c713b124148a5913d25f0b5b7b86e7a39fc3d3bdcf
BLAKE2b-256 checksum
How to use checksums
38806dd3be885f8064278550f195d0a73eddc4973a87ac5b9d607a4cddfa7c1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / gdal_wheel-3.12.4-cp312-cp312-macosx_11_0_arm64.whl

Download URL gdal_wheel-3.12.4-cp312-cp312-macosx_11_0_arm64.whl
Size 18.8 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3de01cf946266657f327e5f82fc40739884cfe5de2897737727874c5b19d7940
BLAKE2b-256 checksum
How to use checksums
34071a734567fb01b9fcbfc244fa2330a5b6d64185ed0d36a0d903495ba060d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.12.4 This release

12 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page