Registry / data / cartopy

cartopy

JSON →
library0.25.0pypypi✓ verified 27d ago

Cartopy is a Python package designed for geospatial data processing and cartographic visualizations, building on Matplotlib. It provides object-oriented projection definitions, transformations between various map projections, and powerful vector data handling. The library is currently at version 0.25.0 and maintains an active release cadence, frequently updating to support modern Python and geospatial libraries.

pip install cartopy
INSTALL
IMPORT
SIG · CARTOPY
C
cartopy
datapythonv0.25.0
Install
9.0s avg
Import
502ms
Disk
238MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.25.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
build_error
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 9.0s · import 0.502s · 231MB
238MB installed
● package 238MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

crs
✓ import cartopy.crs as ccrs
Common alias for Coordinate Reference Systems.
feature
✓ import cartopy.feature as cfeature
Common alias for adding geographical features like coastlines, borders.
GeoAxes
✓ from cartopy.mpl.geoaxes import GeoAxes
Specifically imports the GeoAxes class, often used for type hinting or specific Matplotlib manipulations.

This quickstart creates a basic global map using the Plate Carree projection, adding standard geographical features such as land, ocean, coastlines, country borders, lakes, and rivers. It demonstrates the typical import pattern and usage of `add_subplot` with a Cartopy projection and `add_feature` for geographical elements.

import matplotlib.pyplot as plt import cartopy.crs as ccrs import cartopy.feature as cfeature fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree()) ax.set_global() # Add basic features ax.add_feature(cfeature.LAND) ax.add_feature(cfeature.OCEAN) ax.add_feature(cfeature.COASTLINE) ax.add_feature(cfeature.BORDERS, linestyle=':') ax.add_feature(cfeature.LAKES, alpha=0.5) ax.add_feature(cfeature.RIVERS) plt.title('Basic Cartopy Map with Plate Carree Projection') plt.show()
Debug
Known issues
breakingPython 2 support was removed in Cartopy v0.19. Users on older Python versions must upgrade to Python 3.7+ (v0.20) or 3.10+ (v0.25).
fix
Upgrade your Python environment to version 3.10 or newer.
affects: >=0.19
breakingThe `Axes.natural_earth_shp()` method has been removed. Use `Axes.add_feature()` along with classes from the `cartopy.feature` module instead.
fix
Replace calls like `ax.natural_earth_shp('110m', 'coastline')` with `ax.add_feature(cfeature.COASTLINE)`. Check `cartopy.feature` for other available features.
affects: >=0.16
deprecatedGridliner label control attributes like `Gridliner.xlabels_top`, `xlabels_bottom`, `ylabels_left`, and `ylabels_right` are removed. They were deprecated in v0.18 and removed in v0.23.
fix
Use the replacement attributes: `Gridliner.top_labels`, `bottom_labels`, `left_labels`, or `right_labels`.
affects: >=0.23
breakingThe `cartopy.mpl.clip_path` module is deprecated without replacement, and `path_to_geos`/`geos_to_path` are deprecated in favor of `path_to_shapely`/`shapely_to_path`. This affects low-level path manipulation.
fix
For path conversion, use `cartopy.mpl.path.path_to_shapely` and `cartopy.mpl.path.shapely_to_path`. If `clip_path` functionality is needed, consider vendoring it or finding alternative Matplotlib utilities.
affects: >=0.25
gotchaInstalling Cartopy via `pip` can be challenging due to its complex external (GEOS, PROJ) and Python (Shapely, pyproj) dependencies, especially on Windows or when pre-built wheels are unavailable. Conda is often recommended for a smoother installation.
fix
If `pip install cartopy` fails, try `conda install -c conda-forge cartopy`. For pip, ensure development headers for GEOS and PROJ are installed on your system. Also, ensure `shapely>=2.0` for Cartopy v0.25+.
affects: All
gotchaFrom v0.20, Cartopy uses `pyproj` for transformations, which can sometimes be slower. An environment variable can improve performance.
fix
Set the environment variable `PYPROJ_GLOBAL_CONTEXT=ON` for faster projection calculations if thread safety is not a concern in your application.
affects: >=0.20
gotchaInternal function calls in Cartopy (e.g., for geometries) now prefer `(longitude, latitude)` ordering for consistency.
fix
When passing coordinate pairs to Cartopy functions, ensure they are in `(longitude, latitude)` order, not `(latitude, longitude)`.
affects: >=0.25
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cartopy'
The `cartopy` package is not installed in the active Python environment, or the environment where it was installed is not the one currently being used.
fix
Install Cartopy using conda (recommended, as it handles complex C/C++ dependencies like GEOS and PROJ more robustly) or pip:
`conda install -c conda-forge cartopy`
or
`pip install cartopy`
UserWarning: Unable to determine Proj version. Ensure you have X.Y.Z or later installed, or installation may fail. Proj version 0.0.0 is installed, but cartopy requires at least version X.Y.Z.
Cartopy relies on external C/C++ libraries like PROJ. This error indicates that the PROJ library is either missing, an incompatible version, or its location cannot be found during Cartopy's installation or import, often when installing via `pip` without pre-installed system dependencies.
fix
Use Conda to install Cartopy and its dependencies: `conda install -c conda-forge cartopy`. If using pip on Linux, ensure `libproj-dev` and `proj-data` are installed via your system's package manager (e.g., `sudo apt-get install libproj-dev proj-data proj-bin`). For Windows, installing via a Conda distribution is strongly recommended.
GEOSException: The operation 'GEOSIntersection_r' could not be performed. Likely cause is invalidity of the geometry
This error occurs when geometric operations (e.g., drawing features, contours) encounter invalid or self-intersecting geometries within the underlying `shapely` and `GEOS` libraries that Cartopy uses. It can be triggered by malformed input data or conflicts with specific versions of dependencies like `shapely` or `GEOS`.
fix
Ensure `shapely` and `GEOS` are up-to-date and compatible with your Cartopy version, ideally by installing Cartopy via `conda-forge`: `conda install -c conda-forge cartopy`. If the issue persists with specific data, try simplifying or validating the input geometries using `shapely.geometry.Polygon.buffer(0)` or `shapely.geometry.Polygon.is_valid` to repair topological errors.
Data plotting incorrectly on Cartopy map (wrong location/projection)
When plotting data on a Cartopy `GeoAxes`, the `transform` argument is often omitted or set incorrectly, causing Cartopy to assume the data's coordinate system matches the map's projection, leading to misplaced or distorted data.
fix
Always explicitly specify the `transform` argument in plotting functions (e.g., `ax.contourf`, `ax.plot`, `ax.imshow`) to indicate the coordinate system of your *data*. For example, if your data is in latitude/longitude, use `transform=ccrs.PlateCarree()`.
ImportError: DLL load failed while importing _xxx: The specified module could not be found
This error, common on Windows, indicates that a dynamic-link library (DLL) dependency for Cartopy (or one of its underlying libraries like PROJ or GEOS) cannot be found by Python. This is often due to changes in Python's DLL loading behavior (especially Python 3.8+) or issues with how these binary dependencies are installed.
fix
Install Cartopy using Conda, as it manages these complex binary dependencies reliably: `conda install -c conda-forge cartopy`. If forced to use `pip` on Windows, ensure all external dependencies (PROJ, GEOS, GDAL) are pre-installed correctly and their DLLs are discoverable in the system PATH or via `os.add_dll_directory()` if using Python 3.8+ before importing.
Upgrade
Version history
0.25.0latest on PyPI · released Aug 1, 2025
Audit
Dependencies
pythonrequiredRequired Python version.
matplotlibrequiredEssential for any graphical output.
numpyrequiredCore dependency for scientific computing.
pyprojrequiredPython interface to PROJ (cartographic projections). Required for transformations.
shapelyrequiredPython package for manipulation and analysis of planar geometric objects. Essential for features.
pyshprequiredPure Python read/write support for ESRI Shapefile format.
packagingrequiredUtilities for version handling.
GEOSoptionalUnderlying C++ library for geometric operations (often installed with shapely).
PROJoptionalUnderlying C library for cartographic projections (often installed with pyproj).
gdaloptionalTranslator library for raster/vector geospatial data formats.
PillowoptionalImage processing library, often used for background images.
pykdtreeoptionalFast kd-tree implementation for image warping.
owsliboptionalFor client programming with Open Geospatial Consortium (OGC) web services.
Agent activity
50 hits · last 30 days
node
48
OpenAI (training)
1
Resources
cartopy — pip install cartopy · libregistry