Last modified: Jun 01, 2025 By Alexander Williams

How to Install Rasterio in Python

Rasterio is a Python library for geospatial raster data. It reads and writes geospatial raster files. This guide shows how to install it easily.

What is Rasterio?

Rasterio simplifies working with geospatial raster data. It works with formats like GeoTIFF. It's built on GDAL and NumPy.

Rasterio is useful for GIS applications. It pairs well with Fiona for vector data.

Prerequisites

Before installing rasterio, ensure you have:

  • Python 3.6 or newer
  • pip package manager
  • Basic Python knowledge

Install Rasterio Using pip

The easiest way to install rasterio is with pip. Run this command in your terminal:


pip install rasterio

This downloads and installs the latest stable version. It includes all required dependencies.

Verify the Installation

After installation, verify it works. Open Python and try importing it:

 
import rasterio
print(rasterio.__version__)


1.3.8  # Example output

If you see a version number, installation succeeded. No errors should appear.

Alternative Installation Methods

Using conda

For Anaconda users, install with conda:


conda install -c conda-forge rasterio

Conda handles complex dependencies well. This is good for scientific Python stacks.

From Source

Advanced users can install from source. First clone the repository:


git clone https://github.com/rasterio/rasterio.git
cd rasterio
pip install .

This method requires build tools. It's useful for development contributions.

Common Installation Issues

Some users encounter problems. Here are solutions to common issues.

GDAL Dependency Errors

Rasterio needs GDAL installed. On Linux, install it first:


sudo apt-get install gdal-bin libgdal-dev

On Windows, use pre-built wheels. Or install GDAL from GIS internals.

Permission Errors

If you get permission errors, try:


pip install --user rasterio

This installs for your user only. No admin rights needed.

Basic Rasterio Example

After installation, try this simple example. It opens a raster file:

 
import rasterio

# Open a raster file
with rasterio.open('example.tif') as src:
    print(f"Width: {src.width}")
    print(f"Height: {src.height}")
    print(f"Number of bands: {src.count}")


Width: 1024
Height: 1024
Number of bands: 3

This shows basic raster metadata. Replace 'example.tif' with your file.

Working with Raster Data

Rasterio makes raster operations easy. Here's how to read band data:

 
with rasterio.open('example.tif') as src:
    band1 = src.read(1)  # Read first band
    print(band1.shape)


(1024, 1024)  # Output depends on your image

The read method returns a NumPy array. You can process it with NumPy.

Conclusion

Installing rasterio is straightforward with pip or conda. It's essential for geospatial work in Python.

For shapefile handling, check pyshp. For other geospatial tools, see PyGeoIP.

Now you're ready to work with raster data in Python. Start exploring geospatial analysis today!