5

I want to install Cartopy on Windows, which has some dependencies according to http://scitools.org.uk/cartopy/docs/latest/installing.html#installing. When using pip install cartopy in the cmd prompt, it gives an error where it wants me to install GEOS 3.3.3 and Proj4 4.9.0.

I've downloaded geos-3.6.2.tar.bz2, but I cannot figure out how to install it. I've extracted the files, used cd to the right directory.

What can I do to install it correctly? Is there an easy way to install Cartopy?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
A T
  • 281
  • 3
  • 11
  • *"it gives me an error"*; which error? Installing GEOS manually shouldn't be necessary (and is probably not the best idea....) – Bart Apr 24 '18 at 15:59
  • C:\Users\Me>pip install cartopy Collecting cartopy Using cached https://files.pythonhosted.org/packages/f5/7a/4a16db7c81f11b3c5889c5b913d9a5724c704a6947c5a87ec59c4a8985ac/Cartopy-0.16.0.tar.gz Complete output from command python setup.py egg_info: C:\Users\Me\AppData\Local\Temp\pip-install-5is6l5ec\cartopy\setup.py:178: UserWarning: Unable to determine GEOS version. Ensure you have 3.3.3 or later installed, or installation may fail. '.'.join(str(v) for v in GEOS_MIN_VERSION), )) Proj4 4.9.0 must be installed. – A T Apr 25 '18 at 12:02

5 Answers5

4

Do you have Anaconda?

try:

conda install -c scitools cartopy

Cœur
  • 37,241
  • 25
  • 195
  • 267
Itamar
  • 76
  • 4
  • It worked! Is there any way I could know this, or is this from experience? – A T Apr 25 '18 at 12:01
  • 3
    I would suggest using the conda-forge channel, the scitools channel is out-of date and no longer maintained: `conda install -c conda-forge cartopy`. http://scitools.org.uk/cartopy/docs/latest/installing.html#installing – ajdawson Apr 26 '18 at 17:54
  • adding to this, installing Anaconda can lead to conflicts with the `conda-forge` channel. Instead, I would recommend installing [`miniforge`](https://github.com/conda-forge/miniforge) or [`mambaforge`](https://github.com/conda-forge/miniforge#mambaforge). See e.g. [Can't install cartopy](https://stackoverflow.com/questions/74293754/cant-install-cartopy) – Michael Delgado Dec 06 '22 at 17:31
1

When you are installing through pip then better install using Binary file .Whl extension file You can find all the package binary file below. Especially in case of Cartopy installation through pip, install cartopy using binary wheel file.

https://www.lfd.uci.edu/~gohlke/pythonlibs/

sameer_nubia
  • 721
  • 8
  • 8
1

If you are on Windows and you have installed Anaconda, on your search, type "Anaconda prompt" and then type this command

conda install -c conda-forge cartopy
Kimanthi K.
  • 595
  • 6
  • 13
0

I tried conda install -c conda-forge cartopy

and tried installing it through Anaconda navigator 1.9.12 and I scoured multitude of ways and tried them all and failed. Only this

conda install -c scitools cartopy

works.

I first ran this conda update -n base -c defaults condo following instructions provided among responses here:Updating Anaconda fails: Environment Not Writable Error

0

For what its worth, I managed to build and install cartopy (and cartes) on Windows 10 with python 3.10.9 and Cartopy==0.21.1 :

  • using pip
  • i.e. without anaconda/conda
  • without the tricky global-options stuff as seen here

The base for all of this is to do a custom build of https://libgeos.org

You'll need :

  • powershell console and admin rights, everything below should work within the powershell - EDIT : one can probably use a standard DOS shell using the Visual Studio DOS shell launchers (see edit 2 below)
  • MSVC C++ build tools, possibily visual studio
  • cmake

Procedure

  1. create a fresh ptyhon 3.9 venv

python -m venv venv or py -3.10 -m venv venv

  1. Install Visual Studio and MSVC c++ build tools https://visualstudio.microsoft.com/fr/downloads/

I don't remember which versions I installed ... Retro analysis shows that this was invoked or referenced at some point subsequently to the pip install cartopy command:

MSBuild version 17.5.1+f6fdcf537 for .NET Framework

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\ and child dirs
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ and child dirs

see also Cannot open include file: 'io.h': No such file or directory

  1. Install chocolatey

  2. Open a Powershell console "Developer PowerShell for VS 2022" and activate your venv

venv\Scripts\activate.ps1
  1. Install cmake
chocolatey install cmake
  1. Partially apply procedure indicated here https://libgeos.org/usage/download/ :
  • unzip geos source zip, then go to unzipped dir

I took version 3.11.2, but take whatever suits your needs. I choose to install into %ProgramFiles%, again, take whatever suits you.

cd the_unzip_dir
mkdir _build
cd _build 
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%ProgramFiles%\geos-3.11.2" ..

Cmake will detect the Visual Studio toolsuite and generate a bunch of MSVS project files (*.vcxproj). (What happens if you try without VS but minggw or else ... I don't know.)

  1. Build the Visual Studio projects then perform "installation" step (replaces the "make part from the original tutorial):
msbuild.exe .\ALL_BUILD.vcxproj
msbuild.exe .\INSTALL.vcxproj
  1. Add the installed GEOS directories to the path and env. variables. I am not sure which one is relevant, but it might be relevant at some stage ... (%ProgramFiles% above translates in windows to C:\Program Files (with a space))
set GEOS_INCLUDE_PATH="C:\Program Files\geos-3.11.2\include"
set GEOS_LIBRARY_PATH="C:\Program Files\geos-3.11.2\bin"
set PATH="C:\Program Files\geos-3.11.2\lib";%GEOS_INCLUDE_PATH%;%GEOS_LIBRARY_PATH%;%PATH%
  1. Create include directory inside the python venv and put the built include files into it;

(this is for the pip install stage)

mkdir venv\libs
mkdir venv\include
xcopy /E "%ProgramFiles%\geos-3.11.2\bin" venv\libs
xcopy /E "%ProgramFiles%\geos-3.11.2\lib" venv\libs
xcopy /E "%ProgramFiles%\geos-3.11.2\include" venv\include
pip install cartopy
Building wheels for collected packages: cartopy
  Building wheel for cartopy (pyproject.toml) ... done
  Created wheel for cartopy: filename=Cartopy-0.21.1-cp311-cp311-win_amd64.whl size=10785690 sha256=88a2afb9224263f8269a99a2f71ecc503f105ec54166dcd9c446e3abc61477c1
  Stored in directory: c:\users\<ME>\appdata\local\pip\cache\wheels\e0\34\c2\3c8ace93982cfef7b3b142d6b4f6ef30321b9768a80c115c70
Successfully built cartopy

  1. Now, this is for the venv runtime usage
xcopy /E "%ProgramFiles%\geos-3.11.2\bin" venv\Lib\site-packages\cartopy
xcopy /E "%ProgramFiles%\geos-3.11.2\lib" venv\Lib\site-packages\cartopy
  1. Check runtime imports and usage
pip install cartes
python
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cartopy
>>> import cartopy.trace
>>> from cartes.crs import Lambert93

>>> dir(cartopy.trace)
['CartesianInterpolator', 'Geod', 'Interpolator', 'LineAccumulator', 'ProjError', 'SphericalInterpolator', 'Transformer', '_Testing', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__pyx_unpickle_LineAccumulator', '__spec__', '__test__', '_interpolator', 'lru_cache', 'project_linear', 're', 'sgeom', 'warnings']

>>> print(cartopy.trace.__doc__)

This module pulls together proj, GEOS and ``_crs.pyx`` to implement a function
to project a `~shapely.geometry.LinearRing` / `~shapely.geometry.LineString`.
In general, this should never be called manually, instead leaving the
processing to be done by the :class:`cartopy.crs.Projection` subclasses.

>>>print("Looks fine !")

Resulting pip freeze:

  • Cartopy==0.21.1
  • cartes==0.7.4
  • shapely==2.0.1
  • (no geos :))
pip freeze

aiohttp==3.8.4
aiosignal==1.3.1
altair==4.2.2
appdirs==1.4.4
async-timeout==4.0.2
attrs==23.1.0
beautifulsoup4==4.12.2
cartes==0.7.4
Cartopy==0.21.1
certifi==2022.12.7
charset-normalizer==3.1.0
click==8.1.3
click-plugins==1.1.1
cligj==0.7.2
colorama==0.4.6
contourpy==1.0.7
cycler==0.11.0
entrypoints==0.4
Fiona==1.9.3
fonttools==4.39.3
frozenlist==1.3.3
geopandas==0.12.2
idna==3.4
Jinja2==3.1.2
jsonschema==4.17.3
kiwisolver==1.4.4
lxml==4.9.2
markdown-it-py==2.2.0
MarkupSafe==2.1.2
matplotlib==3.7.1
mdurl==0.1.2
multidict==6.0.4
munch==2.5.0
numpy==1.24.2
packaging==23.1
pandas==2.0.0
Pillow==9.5.0
Pygments==2.15.1
pyparsing==3.0.9
pyproj==3.5.0
pyrsistent==0.19.3
pyshp==2.3.1
python-dateutil==2.8.2
pytz==2023.3
requests==2.28.2
rich==13.3.4
scipy==1.10.1
shapely==2.0.1
six==1.16.0
soupsieve==2.4.1
toolz==0.12.0
tqdm==4.65.0
tzdata==2023.3
urllib3==1.26.15
yarl==1.8.2

EDIT 1 2023-04-22:

It should be better to follow the OSGEO readme instruction for windows build, see osgeo INSTALL.md. NB: one should adapt the Visual Studio version to whatever is appropriate. A Ninja build system command is also provided.

Quoting:

Build with CMake generator for Ninja (fast)

If you prefer the command-line, in the Visual Studio 2019 command prompt, x64 Native Tools Command Prompt for VS 2019 or x64_x86 Cross Tools Command Prompt for VS 2019 run:

cmake -S . -B _build_vs2019_ninja -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build _build_vs2019_ninja -j 16 --verbose

Build with CMake generator for MSBuild (default)

In the non-specific Command Prompt:

64-bit
cmake -S . -B _build_vs2019x64 -G "Visual Studio 16 2019" -A x64 -DCMAKE_GENERATOR_TOOLSET=host=x64
cmake --build _build_vs2019x64 --config Release -j 16 --verbose
32-bit
cmake -S . -B _build_vs2019x32 -G "Visual Studio 16 2019" -A x32 -DCMAKE_GENERATOR_TOOLSET=host=x64
cmake --build _build_vs2019x32 --config Release -j 16 --verbose

EDIT 2 : 2023-04-22

For some reason on another windows 10 machine, the "Visual Studio 2022 PowerShell for Developers" kept references to the Visual Studio x86 build tools (cl.exe), which led pip to build a x86 wheel and try to link x86 with a python x64 environement.

Several options:

  1. Avoid PowerShell and use the appropriate DOS launcher provided by VS install, i.e. for a VS 2022 install, it should be one of:
    • x64 Native Tools Command Prompt for VS 2022
    • x64_x86 Cross Tools Command Prompt for VS 2022
    • x86 Native Tools Command Prompt for VS 2022
    • x86_x64 Cross Tools Command Prompt for VS 2022

i.e.

"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x64 Native Tools Command Prompt for VS 2022.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x64_x86 Cross Tools Command Prompt for VS 2022.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x86 Native Tools Command Prompt for VS 2022.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x86_x64 Cross Tools Command Prompt for VS 2022.lnk"
  1. From a Developper PowerShell, this should do the trick
PS > Launch-VsDevShell.ps1 -Arch amd64
  1. Alternative to 2.

a. Launch a Developer PowerShell b. Determine the Visual Studio instance to use:

# From a Visual Studio Developer Power Shell
# (here I have only one installed, so its pretty easy)
PS > Launch-VsDevShell.ps1 -List
The following Visual Studio installations were found:

# displayName                  instanceId installationVersion isPrerelease installationName              installDate
- -----------                  ---------- ------------------- ------------ ----------------              -----------
1 Visual Studio Community 2022 7c1743f6   17.5.33530.505             False VisualStudio/17.5.4+33530.505 2023-04-20T20:08:47Z


Enter '#' of the Visual Studio installation to launch DevShell. <Enter> to quit: :

b. setup appropriate powershell environment

PS > Enter-VsDevShell 7c1743f6 -DevCmdArguments '-arch=x64 -no_logo'

(no logo is optional ...)

The Start Menu shortcut command was on my machine

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell 7c1743f6}"
LoneWanderer
  • 3,058
  • 1
  • 23
  • 41