Gdal python windows install

The GDAL project distributes GDAL as source code and Containers only. Binaries produced by others are available for a variety of platforms and package managers.

Source Code

Current Release

  • 2025-05-06 gdal-3.11.0.tar.gz 3.11.0 «Eganville» Release Notes (3.11.0 md5)

Past Releases

Links to Past Releases are also available.

Development Source

The main repository for GDAL is located on GitHub at
https://github.com/OSGeo/GDAL.

You can obtain a copy of the active source code by issuing the following
command

git clone https://github.com/OSGeo/GDAL.git

Additional information is available about Build requirements and Building GDAL from source.

Maintenance policy

The GDAL upstream team only maintains the branch on which the latest release has
been done, with bugfixes releases issued roughly every 2 months.
So, for example, during the development phase of GDAL 3.10.0, GDAL 3.9.x bugfixes
releases are done based on the release/3.9 branch, but not older branches (GDAL 3.8.x or older).

Binaries

In this section we list a number of the binary distributions of GDAL
all of which should have fully reproducible open source build recipes.

Note that the maintainers of those distributions are generally not the maintainers
of the GDAL sources, so please report any issue specific to those builds through
their own support channels.

Windows

Windows builds are available via Conda Forge (64-bit only). See the
Conda or pixi section for more detailed information. GDAL is also distributed
by GISInternals and OSGeo4W and through the NuGet and vcpkg package managers.

Linux

Packages are available for Debian, Alpine, Fedora, and other distributions.

Mac OS

GDAL packages are available on Homebrew.

Android

GDAL can be installed using vcpkg. You may also refer to vcpkg Android support for general instructions.

For example to install default configuration for the arm64-android target:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh  # ./bootstrap-vcpkg.bat for Windows
./vcpkg integrate install
export ANDROID_NDK_HOME=/path/to/android_ndk_home  # to adapt
./vcpkg search gdal --featurepackages  # list optional features
./vcpkg install gdal:arm64-android  # install with default configuration
./vcpkg install gdal[poppler,netcdf]:arm64-android  # install with Poppler and netdf support

Cross-Platform Package Managers

Conda

Conda can be used on multiple platforms (Windows, macOS, and Linux) to
install software packages and manage environments. Conda packages for GDAL are
available through conda-forge.

Latest version:

conda install [-c channel] [package...]

GDAL is available as several subpackages:

  • gdal: Python bindings and Python utilities (depends on libgdal-core)

  • libgdal: meta-package gathering all below libgdal-* packages (except libgdal-arrow-parquet)

  • libgdal-arrow-parquet: (Geo)Arrow IPC File Format / Stream and (Geo)Parquet drivers as a plugin (depends on libgdal-core)

  • libgdal-avif: AVIF — AV1 Image File Format driver as a plugin (depends on libgdal-core, available since GDAL 3.10.0)

  • libgdal-core: core library and C++ utilities, with a number of builtin drivers (available since GDAL 3.9.1)

  • libgdal-fits: FITS — Flexible Image Transport System driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-grib: GRIB — WMO General Regularly-distributed Information in Binary form driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-hdf4: HDF4 — Hierarchical Data Format Release 4 (HDF4) driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-hdf5: HDF5 — Hierarchical Data Format Release 5 (HDF5) driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-heif: HEIF / HEIC — ISO/IEC 23008-12 High Efficiency Image File Format driver as a plugin (depends on libgdal-core, available since GDAL 3.10.0)

  • libgdal-jp2openjpeg: JP2OpenJPEG — JPEG2000 driver based on OpenJPEG library driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-kea: KEA driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-netcdf: NetCDF: Network Common Data Form driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-pdf: PDF — Geospatial PDF driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-postgisraster: PostGISRaster — PostGIS Raster driver driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-pg: PostgreSQL / PostGIS driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-tiledb: TileDB — TileDB raster driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

  • libgdal-xls: XLS — MS Excel format driver as a plugin (depends on libgdal-core, available since GDAL 3.9.1)

To install the gdal package (Python bindings and utilities), and libgdal-core:

conda install -c conda-forge gdal

To install the libgdal meta-package with all available drivers, but libgdal-arrow-parquet:

conda install -c conda-forge libgdal

To install the Arrow and Parquet drivers as plugins:

conda install -c conda-forge libgdal-arrow-parquet
GDAL master Conda builds

GDAL master builds are available in the gdal-master
channel. They are based on dependencies from the conda-forge channel. The latest master
build can be installed with the following command:

conda install -c gdal-master -c conda-forge gdal-master::gdal

As with released versions of GDAL, additional drivers can be installed using gdal-master::libgdal-{driver_name}.

pixi

Pixi is a package management tool for developers. It allows the developer
to install libraries and applications in a reproducible way. Packages for GDAL are
available through the conda-forge channel.

If you want to be able to use GDAL as part of a project:

pixi init name-of-project
cd name-of-project
pixi add gdal libgdal-core
pixi add libgdal-arrow-parquet # if you need the Arrow and Parquet drivers
pixi shell

Pixi supports using tools like GDAL and OGR globally, similar to conda’s base environment, without having to use an activate command:

pixi global install gdal libgdal-core
pixi global install libgdal-arrow-parquet # if you need the Arrow and Parquet drivers

vcpkg

The GDAL port in the vcpkg dependency manager is kept up to date by Microsoft team members and community contributors.
You can download and install GDAL using the vcpkg as follows:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh  # ./bootstrap-vcpkg.bat for Windows
./vcpkg integrate install
./vcpkg search gdal --featurepackages  # list optional features
./vcpkg install gdal  # install with default configuration
./vcpkg install gdal[poppler,netcdf]  # install with Poppler and netdf support

If the version is out of date, please create an issue or pull request on the vcpkg repository.

Spack

Spack is a package management tool designed to support multiple versions and
configurations of software on a wide variety of platforms and environments.
It was designed for large supercomputing centers. Spack builds packages from
sources, and allows tweaking their configurations.

You can find information about GDAL in Spack at
https://packages.spack.io/package.html?name=gdal

For the default GDAL build with a reduced number of drivers:

git clone -c feature.manyFiles=true https://github.com/spack/spack.git
cd spack/bin
./spack install gdal

For a build with netcdf driver enabled:

./spack install gdal +netcdf

Containers

Docker images with nightly builds of GDAL master and tagged releases are available at
GitHub Container registry.

Information on the content of the different configurations can be found at
https://github.com/OSGeo/gdal/tree/master/docker.

Documentation

This documentation is also available as a PDF or a ZIP of individual HTML pages for offline browsing.

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. There is no Python specific
reference documentation, but the https://gdal.org/api/python_bindings.html#tutorials includes Python examples.

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.11.0 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 packging 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/en/latest/

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

API documentation is available at https://gdal.org/api/python/osgeo.html

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

See https://gdal.org/api/python_bindings.html#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 https://gdal.org/api/python_gotchas.html

Examples

  • An assortment of other samples are available in the Python github samples directory
    with some description in the https://gdal.org/api/python_bindings.html#examples.

  • Several GDAL utilities
    are implemented in Python and can be useful examples.

  • The majority of GDAL regression tests are written in Python. They are available at
    https://github.com/OSGeo/gdal/tree/master/autotest

One example of GDAL/numpy integration is found in the val_repl.py script.

This recipe shows how to install gdal in your Windows Environment

Prerequisites

To run this code you need:
  • A running Python 3.x Environment

  • Know if your computer is 32 bit or 64 bit

Recipe

Often GDAL is a very important library to manipulate satellite data.

Note

You can find the architecture of your PC going in: Settings -> System -> About

To install GDAL:

  • Open the web page https://github.com/cgohlke/geospatial-wheels/releases

  • If needed, click on the small “Show all XXX assets” link to expand the list

  • Identify your GDAL wheel

Note

A sample is: GDAL-3.9.2-cp312-cp312-win_amd64.whl

GDAL-3.9.2: means gdal version 3.9.2

cp312-cp312: means build for python 3.12

win_amd64: means a 64 bit windows

You can find the version of gdal you need for your python version.

Both Intel and AMD Processors are in the amd64 architecture

  • Download GDAL wheel, in this tutorial we will assume GDAL-3.9.2-cp312-cp312-win_amd64.whl

  • Open your python environment

  • Install the wheel:

pip install "C:\Users\YOUR_USER\Downloads\GDAL-3.9.2-cp312-cp312-win_amd64.whl"

Now, you should be able to import gdal in your code.

Note

You may have still a problem when running a python script with gdal.

If you see this error:

ImportError: DLL load failed while importing _gdal: The specified module could not be found.

This probably means that you are missing the VC — redist libraries.

These can be found here:

This is the direct link to the version for x64 Machines:

GDAL/OGR in Python

This Python package and extensions are a number of tools for programming and
manipulating the GDAL Geospatial Data Abstraction Library. Actually, it is
two libraries — GDAL for manipulating geospatial raster data and OGR for
manipulating geospatial vector data — but we’ll refer to the entire package
as the GDAL library for the purposes of this document.

The GDAL project (primarily Even Rouault) maintains SWIG generated Python
bindings for GDAL and OGR. Generally speaking the classes and methods mostly
match those of the GDAL and OGR C++ classes. There is no Python specific
reference documentation, but the GDAL API Tutorial includes Python examples.

Dependencies

  • libgdal (3.3.0 or greater) and header files (gdal-devel)
  • numpy (1.0.0 or greater) and header files (numpy-devel) (not explicitly
    required, but many examples and utilities will not work without it)

Installation

Unix

The GDAL Python bindings support both distutils and setuptools, with a
preference for using setuptools. If setuptools can be imported, setup will
use that to build an egg by default. If setuptools cannot be imported, a
simple distutils root install of the GDAL package (and no dependency
chaining for numpy) will be made.

easy_install

GDAL can be installed from the Python CheeseShop:

$ sudo easy_install GDAL

It may be necessary to have libgdal and its development headers installed
if easy_install is expected to do a source build because no egg is available
for your specified platform and Python version.

setup.py

Most of setup.py’s important variables are controlled with the setup.cfg
file. In setup.cfg, you can modify pointers to include files and libraries.
The most important option that will likely need to be modified is the
gdal_config parameter. If you installed GDAL from a package, the location
of this program is likely /usr/bin/gdal-config, but it may be in another place
depending on how your packager arranged things.

After modifying the location of gdal-config, you can build and install
with the setup script:

$ python setup.py build
$ python setup.py install

If you have setuptools installed, you can also generate an egg:

$ python setup.py bdist_egg

Building as part of the GDAL library source tree

You can also have the GDAL Python bindings built as part of a source
build by specifying —with-python as part of your configure line:

$ ./configure --with-python

Use the typical make and make install commands to complete the installation:

$ make
$ make install

A note about setuptools

./configure attempts to detect if you have setuptools installed in the tree
of the Python binary it was given (or detected on the execution path), and it
will use an egg build by default in that instance. If you have a need to
use a distutils-only install, you will have to edit setup.py to ensure that
the HAVE_SETUPTOOLS variable is ultimately set to False and proceed with a
typical ‘python setup.py install’ command.

Windows

You will need the following items to complete an install of the GDAL Python
bindings on Windows:

  • GDAL Windows Binaries Download the package that best matches your environment.

As explained in the README_EXE.txt file, after unzipping the GDAL binaries you
will need to modify your system path and variables. If you’re not sure how to
do this, read the Microsoft Knowledge Base doc

  1. Add the installation directory bin folder to your system PATH, remember
    to put a semicolon in front of it before you add to the existing path.

    C:\gdalwin32-1.7\bin
    
  2. Create a new user or system variable with the data folder from
    your installation.

    Name : GDAL_DATA
    Path : C:\gdalwin32-1.7\data
    

Skip down to the Usage section to test your install. Note, a reboot
may be required.

SWIG

The GDAL Python package is built using SWIG. The earliest version of SWIG
that is supported to generate the wrapper code is 1.3.40. It is possible
that usable bindings will build with a version earlier than 1.3.40, but no
development efforts are targeted at versions below it. You should not have
to run SWIG in your development tree to generate the binding code, as it
is usually included with the source. However, if you do need to regenerate,
you can do so with the following make command from within the ./swig/python
directory:

$ make generate

To ensure that all of the bindings are regenerated, you can clean the
bindings code out before the generate command by issuing:

$ make veryclean

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

Additionally, there are five compatibility modules that are included but
provide notices to state that they are deprecated and will be going away.
If you are using GDAL 1.7 bindings, you should update your imports to utilize
the usage above, but the following will work until GDAL 3.1.

>>> import gdal
>>> import ogr
>>> import osr
>>> import gdalnumeric
>>> import gdalconst

If you have previous code that imported the global module and still need to
support the old import, a simple try…except import can silence the
deprecation warning and keep things named essentially the same as before:

>>> try:
...     from osgeo import gdal
... except ImportError:
...     import gdal

Docstrings

Currently, only the OGR module has docstrings which are generated from the
C/C++ API doxygen materials. Some of the arguments and types might not
match up exactly with what you are seeing from Python, but they should be
enough to get you going. Docstrings for GDAL and OSR are planned for a future
release.

Numpy

One advanced feature of the GDAL Python bindings not found in the other
language bindings (C#, Perl) 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.

Examples

One example of GDAL/numpy integration is found in the val_repl.py script.

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.

Installing GDAL for Python with pip , the package installation package, is not as easy as it may seem. If you try to install GDAL to a python environment with a command like python -m pip install gdal it will initially seem like the installation is going to happen. However, you will receive a message that pip failed to build the python wheel file, then a long, verbose error message. Not to worry. You can still install gdal with pip, and here’s how to do it. You can also check out the video at the end of this article for a demonstration. Once you get GDAL installed, check out our tutorial to get started using GDAL with Python. You can also check out my full GDAL for Python course to get step-by-step explanations complete with code and datasets for performing raster analysis with GDAL.

If you want to install gdal to a conda (Anaconda) environment you can follow my tutorial for installing gdal with conda. Anaconda users can also follow this tutorial but the conda method is recommended.

First, let’s understand why the problem occurs. GDAL is actually a C++ library with python bindings. That means it relies on underlying C++ code and the package must be built/compiled in a certain manner to be usable with Python. GDAL is an open-source project, and depending on the user group and other applications there may not be resources to provide a python-specific distribution or other considerations that prevent it. The upside is that because it is open-source anyone can develop a solution, and I’ll explain one now.

1. Download a pre-built gdal wheel file

With pip we can use a wheel file to install a package. Wheel files contain all the information needed to install a python package. Often when pip is used for install it downloads a wheel file for the install. A gdal wheel file can be obtained from Christoph Gohlke’s website. You’ll need to select the file that matches your specific Python version and operating system (32 or 64 bit). Once you find the appropriate file download it to a location you remember

2. Install the wheel file with pip

Now all you have to do is install the wheel file with pip. I recommend navigating the directory where you downloaded the file (with cd) before running the command below. Alternatively, you can stay in your current directory and pass the full path of the wheel file.

python -m pip install path-to-wheel-file.whl

Assuming that you’ve used the appropriate wheel file, this should successfully install gdal

3. Test the installation

Now make sure you can load gdal in a python session. From the command prompt type python to start an interactive session. Once the session has started you will see a description of your python version followed by >>> indicating that the next code you type will be interpreted by python.

Type from osgeo import gdal and hit Enter. If nothing happens then gdal was successfully imported. If you get an error message something obviously went wrong. You may also want to try import gdal, especially for older python versions.

Conclusion

Hopefully, this guide has helped you get gdal running for Python. Check out our guide to getting started with GDAL to make the most of your new installation. If you’re still having issues you may want to try creating a new, clean environment for your gdal installation. If you’re not using an Anaconda Python distribution you may want to try that and use the conda guide to install gdal.

Want to learn more about GDAL?

I have a full-length course on using GDAL for raster analysis with Python. The course contains six hours of video instruction and is complete with code and example datasets so you can easily follow along and replicate the concepts that are taught. Check it out at geospatialschool.com!

Whether you’re looking to take your GIS skills to the next level, or just getting started with GIS, we have a course for you! We’re constantly creating and curating more courses to help you improve your geospatial skills.

All of our courses are taught by industry professionals and include step-by-step video instruction so you don’t get lost in YouTube videos and blog posts, downloadable data so you can reproduce everything the instructor does, and code you can copy so you can avoid repetitive typing


My Recommended Equipment

Computer: Dell XPS

Mouse: Logitech M557 Bluetooth Mouse

External Hard Drive: Seagate Portable 2TB


This article contains affiliate links. When you click on links in this article Open Source Options may make a commission on any sales. This does not have any impact on the price you pay for products.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Sony vegas for windows 7 64 bit
  • Сетевая служба microsoft windows
  • Очистить кэш пользователя на сервере windows
  • Последний релиз windows 11 pro
  • Как установить elementary os вместе с windows