Install rasterio For Windows With pip or conda
The most used python package for reading and writing raster data is probably rasterio
. The rasterio
package wraps around the Geospatial Data Abstraction Library (GDAL, also available as a python package) to provide core functionality for accessing raster data.
As with gdal
(guide for GDAL installation here), installing rasterio
for python on Windows is not as simple as running pip install rasterio
. There are dependable ways to install rasterio
using both pip
and conda
. This article describes each method below in detail.
Install rasterio
with pip
There are a couple of reasons why you will get errors if you try to run the command pip install rasterio
as you would with most python packages. First, rasterio
depends on gdal
and if you’ve ever installed gdal
for python (on Windows) you know it must be installed from a wheel file or compiled from source code. Second, rasterio
must also be installed from a wheel file or compiled from source (see documentation here).
If you do run the command pip install rasterio
you’ll probably get an error message that contains at least some of the following text.
ERROR: Command errored out with exit status 1:
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.
Don’t worry. To install with pip
we just need to download the wheel files for gdal
and rasterio
and use them for the install.
You can access unofficial wheel files from this site. Note that this website is kind of the official unofficial source for python wheel files. Make sure you download the wheel files for both gdal
and rasterio
. The numbers in the filename correspond to the python version (38 = python version 3.8) and operating system architecture (64 for 64-bit).
Once you have the wheel files downloaded install them with pip as follows. Be sure to install gdal
first, then rasterio
. To make things easy use the command prompt and cd
to the directory whey you have downloaded the wheel files, then install with the following commands.
pip install GDAL‑3.3.3‑cp38‑cp38‑win_amd64.whl
pip install rasterio‑1.2.10‑cp38‑cp38‑win_amd64.whl
After using the above commands to install the downloaded wheel files you should be able to use rasterio
successfully. You do not need to import gdal
to use rasterio
.
import rasterio
Install rasterio
with conda
Installation of rasterio
with conda is simple. The rasterio
package is available from the conda-forge anaconda channel so we just need to specify that channel during the install.
It’s recommended to not install rasterio
to the ‘base’ conda environment. Instead, create a new environment or install it to an environment you have already created. This guide will walk you through installing Anaconda and creating an environment.
Once you have created a conda environment use this line of code to install rasterio
conda install -c conda-forge rasterio
Now you should be able to use rasterio
in your scripts and applications.
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