How to Install GDAL for python in windows.
GDAL is the Geospatial Data Abstraction Library. It is a tool that can be used to manipulate spatial data. In the past, I have tried many ways to seamlessly install GDAL in a computer running on windows and it has proven to be a hectic task. Most of the methods I tried were so complicated and a beginner would be stuck and sometimes the installation will not happpen correctly. I therefore have arrived at a straight-forward way to install GDAL in a windows computer. Follow for the specific steps.
Check your python version
GDAL wheels are built for specific python versions. You want to make sure that the GDAL version you are installing coincides with your python version. To check python version, run the following command in the command prompt:
python --version
This command will return the python version. From my computer, the following is shown
Python 3.9.7
Create a new Virtual Environment
Python virtual environments are ways that python developers separate project dependencies. It is therefore good practice to create the new environment for every new project/app.
You can therefore install, create a new environment named venv and activate it as using the following commands, running them one after the other:
pip install virtualenvwrapper
installs the virtual environment
mkvirtualenv venv
creates the virtual environment
venv\Scripts\activate
activates the virtual environment
Download the GDAL Wheel using the browser
To download the GDAL wheel, you can open the Christoph Gohlke site for unofficial windows binaries for python extension packages using this link.
lfd.uci.edu/~gohlke/pythonlibs
Once the page is loaded. Search "GDAL" on the list by scrolling downwards.
The list, as of the time of writting looks like as shown in the following image:
Note the naming system of these wheels.
For my system, I will download the following file: GDAL‑3.3.2‑cp39‑cp39‑win_amd64.whl
The naming system of this wheel is explained as follows:
GDAL - 3.3.2 means GDAL version 3.3.2
cp39 - means this package is for python version 3.9
win_amd64 means its for windows 64 bit.
Make sure to download the one that coincides with your system, otherwise, you might run into errors.
Download this package into the downloads folder and once the download is complete, copy the path to the downloaded file, including the file name and the file extenstion (.whl)
For my system, the path to this file is as follows:
C:\Users\Thuha\Downloads\GDAL‑3.3.2‑cp39‑cp39‑win_amd64.whl
Now open the command prompt, with your virtual environment activated and type the following on the command propmt:
python -m pip install C:\Users\Thuha\Downloads\GDAL‑3.3.2‑cp39‑cp39‑win_amd64.whl
Note that the directory might be different from yours so change this accordingly
GDAL will be installed in your windows virtual environment.
Test that the installation worked correctly by opening the python interactive shell on the command prompt by typing python
And on the interactive shell, type:
from osgeo import gdal
gdal.VersionInfo()
The following picture shows my output from this shell:
If you see this, Congratulations!! You have installed GDAL correctly.
In case your case did not work, you can email me directly to me@josephthuha.tech or comment down below and I will be happy to help.
Thanks for following.