How to create a Python 3.x Virtual Environment using Pipenv and install the GDAL library for Spatial Data Science without OSGeo4W
Geospatial Data Abstraction Library (GDAL) is a library for translating raster and vector geospatial data formats. The library is written in C/C++ and hence for it to work with Python a wrapper class is written that wraps around the GDAL to allow its methods to be accessible.
More often than not, the installation of GDAL in Windows OS powered computers is painful and mostly fails especially when using Python virtual environments. In the next steps I will take you through installing GDAL in a virtual environment in Windows operating system, Python 3.x and Pipenv virtual environment.
Watch the video at Install GDAL in Windows 10 Python Environment and Like the video and Subscribe for more content.
For this installation you should be familiar with command line or Windows PowerShell to interact with your computer. Windows PowerShell is used in this tutorial with Python 3.8
mkdir D://spatial_data_science
Change into the created folder using the change directory command.
cd D://spatial_data_science
Install Pipenv using python command below.
py -m pip install pipenv
Create a Pipenv virtual environment associated with the current folder and activate it.
#Instantiate a virtual environment
py -m pipenv install
#Activate the virtual environment
py -m pipenv shell
Download the GDAL version binaries that correspond to your installed python version win32(x86) or win64(x64) from Python Extension Packages for Windows - Christoph Gohlke (uci.edu) .
For example: GDAL-3.2.2-cp38-cp38-win_amd64.whl downloads GDAL-3.2.2-cp38-cp38-win_amd64.whl binary which is intended for x64 Python 3.8 installation.
Install the downloaded binary to your virtual environment through pip command in Windows PowerShell:
#pip install path\to\your\downloaded\file\filename
#For example:
pip install c:\users\johhny\Downloads\GDAL-3.2.2-cp38-cp38-win_amd64.whl
After this process the GDAL library is fully installed to your virtual environment and is ready to use with other libraries like Geopandas and Rasterio .
If you like this post check my YouTube Channel for more videos on Spatial Data Science.