Installing rasterio in Windows

I recently had to use Python’s rasterio library for a project. I tried the usual pip approach:

pip install rasterio

However, I got an error similar to the following:

INFO:root:Building on Windows requires extra options to setup.py to locate needed GDAL files. More information is available in the README.
ERROR: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.

After spending some time on Google, I found this hack that helped me circumvent this problem and hopefully it will work for you as well.

Step 1: Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/

This contains a collection of Unofficial Python Binaries for Windows, by  Christoph Gohlke.

Step 2: Search for GDAL and rasterio on this page

You will find several wheel files for both of these.

The number following the library name refers to the version of the library. The number following cp represents the python version. So cp34 refers to Python 3.4, and so on. Finally, at the end the Windows type is mentioned (32-bit/ 64-bit).

Thus, GDAL‑3.0.4‑cp36‑cp36m‑win_amd64.whl means GDAL version 3.0.4 for Python 3.6, for 64-bit windows.

Step 3: Download the .whl files compatible with your python version and Windows version

I am on a 64-bit Windows machine and using Python3.8. Therefore, I downloaded

  1. GDAL‑3.2.2‑cp38‑cp38‑win_amd64.whl
  2. rasterio-1.2.1-cp38-cp38-win_amd64.whl

Note down the path of these two files. In my case, they were stored in the Downloads folder.

Step 4: Install these two .whl files using the pip install

Open your command prompt and run the following commands

pip install <path to GDAL .whl file>
pip install <path to rasterio .whl file>

For example, in my case, to install the GDAL file, I had to run the following command:

pip install C:\Users\Yash\Downloads\GDAL-3.2.2-cp38-cp38-win_amd64.whl

Now your rasterio library should be installed. You can open python and try running

import rasterio

This should not give you any error now.

I hope this post helped. You can read more python related posts here: https://iotespresso.com/tag/python/.


If you are interested in data science and machine learning using Python, you may find this course by Jose Portilla on Udemy to be very helpful. It has been the foundation course in Python for me and several of my colleagues.

3 comments

    1. Hi- I followed similar steps as mentioned above, still getting no module error! could you please help me with this errror?

Leave a comment

Your email address will not be published.