Last modified: Jun 01, 2025 By Alexander Williams

Install Cartopy in Python Easily

Cartopy is a Python library for geospatial data visualization. It makes creating maps easy. It works well with Matplotlib.

This guide will show you how to install Cartopy. You will also learn basic usage examples.

Prerequisites for Cartopy

Before installing Cartopy, you need some dependencies:

Python 3.6 or higher is required. You should also have pip installed. Basic Python knowledge helps.

For geospatial work, you might need GeoPandas or Fiona.

Install Cartopy Using pip

The easiest way to install Cartopy is with pip. Run this command:


pip install cartopy

This will download and install Cartopy. It will also install required dependencies.

Verify Cartopy Installation

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


import cartopy
print(cartopy.__version__)

This should print the installed version. No errors means it works.

Common Installation Issues

Some users face installation problems. Here are common fixes:

Missing dependencies: Cartopy needs GEOS and PROJ. On Linux, install them first.

For Ubuntu/Debian:


sudo apt-get install libgeos-dev proj-bin

For Windows, use conda instead of pip. It handles dependencies better.

Basic Cartopy Example

Here's a simple map example using Cartopy:


import matplotlib.pyplot as plt
import cartopy.crs as ccrs

fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.coastlines()
plt.title("Basic World Map")
plt.show()

This code shows a world map with coastlines. The PlateCarree projection is used.

Cartopy with Other Libraries

Cartopy works well with other geospatial libraries. You can use it with Basemap or Rasterio.

For shapefile support, consider pyshp.

Conclusion

Installing Cartopy is straightforward with pip. It's powerful for geospatial visualization.

Remember to install dependencies first if you have issues. Cartopy works best with other geospatial Python libraries.

Now you're ready to create beautiful maps in Python!