8

I am trying to install Cartopy on Windows. I have installed all the dependencies from their website, however when I go to run

pip install Cartopy

I get:

 Complete output (5 lines):
  setup.py:117: UserWarning: Unable to determine GEOS version. Ensure you have 3.7.2 or later installed, or installation may fail.
    warnings.warn(
  setup.py:166: UserWarning: Unable to determine Proj version. Ensure you have 8.0.0 or later installed, or installation may fail.
    warnings.warn(
  Proj version 0.0.0 is installed, but cartopy requires at least version 8.0.0

I have ran and succesfully completed

pip install proj
pip install geos
CeilingSystems
  • 167
  • 1
  • 9

3 Answers3

20

Installing Cartopy on Windows using pip is not trivial. Nevertheless, here is a cartopy installation overview using the method that worked for me, specifically for Windows and without using conda.

  1. Start by uninstalling proj, geos, and shapely if they are already installed, otherwise skip to step 2. This will facilitate linking them in later steps. pip uninstall shapely pip uninstall proj pip uninstall geos

  2. Install proj and geos from OSGeo4W. You cannot use pip to install these because pip points to other projects of the same name. Instead, use the OSGeo4W installer: https://trac.osgeo.org/osgeo4w/ Run as admin and use all the default options, including default installation directories (Advanced Install -> Install from Internet -> All Users -> Next -> Direct Connection -> download.osgeo.org). Then search proj, expand Libs and click the top two "skip"s (proj and proj-data) once each to toggle to the latest release. Now search geos, expand Libs again, and toggle the first "skip" (geos) once to the latest version. Then click next, allow the installer to load dependencies, and click next. The installation took ~5 minutes for me. You now have proj and geos installed.

  3. Install shapely from the .whl. You cannot use the method listed in the cartopy install instructions; it fails to link shapely to geos and you will get an error when importing cartopy. Instead, head to https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely and download the version that suits your python installation (e.g. if you run 64-bit python 3.10, download Shapely‑1.8.1.post1‑cp310‑cp310‑win_amd64.whl) Now you can run pip install \{path}\{to}\{whl}\{Shapely_file.whl}

  4. Install cartopy from the .whl. You can download one that suits you here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#cartopy Pick the one that suits your system (e.g. if you run 64-bit python 3.10, download Cartopy‑0.20.2‑cp310‑cp310‑win_amd64.whl) Now you can run pip install \{path}\{to}\{whl}\{Cartopy_file.whl}

That's it! It took me a long while and sifting through at least a couple dozen "just use conda" threads to figure this out.

Select relevant discussions: https://github.com/SciTools/cartopy/issues/1471 https://towardsdatascience.com/install-shapely-on-windows-72b6581bb46c

jlave
  • 226
  • 3
  • 7
  • A FYI. The wheels from Gohlke have stopped updating since June 26 2022 and the packages are starting to become outdated. AFAIK no other platforms have tried adapting the python packages for Windows. – MorningGlory Jun 20 '23 at 16:31
0

The answer provided by jlave worked great in installing Cartopy.

In order to successfully import Cartopy after its installation, pyproj needed to be installed from the same site as shapely.

If this step is not included I am getting the following error:

ImportError: DLL load failed while importing trace: The specified module could not be found. 

For cartopy.crs and cartopy.trace

Aqua_George
  • 434
  • 1
  • 5
  • 9
-4

Do yourself a favour and use conda (or even better mamba) to manage your package-dependencies!

1 line and it will work out of the box in Windows, MacOS and Linux.

conda install -c conda-forge cartopy

Managing dependencies yourself is tedious and error-prone, especially when it comes to c or c++ dependencies (which is the case for geo-libraries such as pyproj or gdal)

... it's also what cartopy recommends in their docs!

raphael
  • 2,159
  • 17
  • 20
  • I didn't downvote, but I prefer pip because it does the job in a *minimal* way -- doesn't install zillions of packages when you want only a few, and can update only a few. Packages that pip can't install are, for me, too big / too old anyway. In any case, do NOT mix pip and conda trees -- that's asking for trouble. – denis May 05 '23 at 10:09
  • If you know what you're doing, it comes down to "whatever you prefer"... but looking at the accepted answer (which starts with "its not trivial") in comparison to how trivial it is on any OS with `conda/mamba` I don't get why people prefer messing with `pip` + custom installers/wheels (especially on windows). Installing "zillions of packages" basically means "getting the dependencies right" (and there's `--force` and `--no-deps` flags to override). The claim that conda-packages are big/old is simply wrong. Many `conda-forge` packages just use the pip src with more comprehensive setup scripts. – raphael May 06 '23 at 11:22
  • ... also it is the officially recommended way to install `cartopy` and even `pyproj`, `pygeos`, `numpy`, `pandas` ,`shapely`, `geopandas` etc. mention `conda` as a more simple way on how to install in their docs... I get that some experienced users might want to stick to `pip`-only installs... but from my experience, newcomers often just get overwhelmed by it or fail trying. (while they can get a fully operational environment in a few minutes with `conda/mamba` ... and both are also 100% free and open-source) – raphael May 06 '23 at 11:56