Sam Hooke

Installing Cartopy on Ubuntu

The Python package Cartopy has some external dependencies, meaning installation is more complicated than just pip install cartopy. The official documentation is a great starting point for Ubuntu, but you may need to follow additional steps for the external dependencies.

Cartopy requires GEOS and PROJ, which on Ubuntu are provided by the packages libgeos-dev and proj-bin respectively.

Specifically, Cartopy requires PROJ v8.0.0 or greater. The version of PROJ provided by apt-get install depends upon the version of Ubuntu. On Ubuntu 22.04, PROJ v8.2.1 is available, so we can just apt-get install. However, on Ubuntu 20.04, the older release PROJ v6.3.1 is available. To ensure we have PROJ v8.0.0 or greater, we will build PROJ from source1.

These notes cover installing Cartopy v0.20.3 on both Ubuntu 20.04 and Ubuntu 22.04, with PROJ v9.0.0.

Installing Cartopy on Ubuntu 20.04 §

  1. Install GEOS:
sudo apt-get install libgeos-dev
  1. Install build dependencies for PROJ:
sudo apt-get install cmake sqlite3 libsqlite3-dev curl libcurl4-openssl-dev libtiff-dev
  1. Download and extract PROJ2:
wget https://download.osgeo.org/proj/proj-9.0.0.tar.gz
tar -xf proj-9.0.0.tar.gz
cd proj-9.0.0/
  1. Build and install PROJ:
mkdir build
cd build
cmake ..
cmake --build .
sudo cmake --build . --target install
  1. Install Cartopy.
pip install cartopy

Done.

Installing Cartopy on Ubuntu 22.04 §

  1. Install GEOS and PROJ:
sudo apt-get install libgeos-dev proj-bin
  1. Install Cartopy.
pip install cartopy

Done - that’s it!

Troubleshooting §

Unable to determine GEOS version §

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [3 lines of output]
      /tmp/pip-install-han_3_qr/cartopy_4e070ca470124349b5ccf355fd59553c/setup.py:120: UserWarning: Unable to determine GEOS version. Ensure you have 3.7.2 or later installed, or installation may fail.
        '.'.join(str(v) for v in GEOS_MIN_VERSION), ))
      Proj 8.0.0 must be installed.
      [end of output]

Make sure to install GEOS, e.g. sudo apt-get install libgeos-dev.

Could NOT find TIFF §

CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.22/Modules/FindTIFF.cmake:124 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:193 (find_package)

Make sure to install a TIFF library, e.g. sudo apt-get install libtiff-dev.

Proj 8.0.0 must be installed §

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      Proj 8.0.0 must be installed.
      [end of output]

  1. Thanks to Recessive for pointing this out↩︎

  2. At time of writing, Cartopy requires PROJ v8.0.0 or later. We are installing PROJ v9.0.0. See here for all available releases of PROJ. ↩︎

See all notes.

← Previous Note: Memory allocation error in WAV files created by arecord
Next Note: GitLab CI: Using a private project's container as an image →