Closed veenstrajelmer closed 4 years ago
You do not have the required dependencies for cartopy installed. Cartopy requires two C++ libraries, geos (https://trac.osgeo.org/geos/) and proj (https://proj.org/), to be available. Unfortunately there happen to be two completely different packages in PyPI that use these same names (https://pypi.org/project/geos/ and https://pypi.org/project/proj/), which is what you have installed. The correct libraries cannot be installed with pip as far as I know.
I'm not a Windows user so I'm not exactly sure which is the best way to get you up and running from this point. Do you have any ideas @QuLogic?
Thanks for your response. The same names indeed confused me, thanks for the clarification. I was aware that the dependencies were not installed, but I am used to pip solving this for me of course. It seems however that pip cannot reach the dependencies, which is inconvenient. Does this mean that I cannot install cartopy via pip at all? Then I will have to a conda install, since this does do the trick. This would however mean that I cannot include cartopy as requirement the setup.py of my own package.
You can also get binaries from Christoph Gohlke: https://www.lfd.uci.edu/~gohlke/pythonlibs/
There cannot be any binaries until we solve #805. Closing as a dupe of #1174.
hi.
i have gotten geos and proj library from OSGeo4W on windows. then, set PATHs of \bin
(include dll) and \include
(includes such as geos_c.h
) . however, follow error happens:
> pip install cartopy
trace.cpp
lib/cartopy/trace.cpp(665): fatal error C1083: include ファイルを開けません。'geos_c.h':No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Failed building wheel for cartopy
how can i solve to set ?
@Cartman0 the solution to that is to specify the include and library directories when calling pip install. Assuming you've used the default OSGeo4W install directory, this would be:
pip install --global-option=build_ext --global-option="-IC:\OSGeo4W\include" --global-option="-LC:\OSGeo4W\lib" cartopy
Pip will then pass these options to MSVC. See this SO post
HTH
conda install -c conda-forge cartopy works well and solves the problem in my windows computer.
conda install -c conda-forge cartopy works well and solves the problem in my windows computer.
It returns with "No module named 'conda._vendor.tqdm.version' " although tqdm is already install and if tried to install again it says requirement already satisfied.
@prakash023 That sounds like your conda install is broken. It might be easiest to re-install Anaconda or miniconda.
Thanks for your response. The same names indeed confused me, thanks for the clarification. I was aware that the dependencies were not installed, but I am used to pip solving this for me of course. It seems however that pip cannot reach the dependencies, which is inconvenient. Does this mean that I cannot install cartopy via pip at all? Then I will have to a conda install, since this does do the trick. This would however mean that I cannot include cartopy as requirement the setup.py of my own package.
Hello, have you solved the problem? I met the same trouble.
@dengwanxia1991 You could install cartopy from https://www.lfd.uci.edu/~gohlke/pythonlibs/. Note that all the dependencies such as Shapely
must also be installed from the website.
The easiest solution is to create a new virtual environment and importing the geopackages like rasterio or cartopy in it.
For what its worth, I managed to build and install cartopy (and cartes) on Windows 10, python 3.10.9 :
global-options
stuff (see comment above recommending pip install --global-option=build_ext --global-option="-IC:\OSGeo4W\include" --global-option="-LC:\OSGeo4W\lib" cartopy
which did not work for me)The base for all of this is to do a custom build of https://libgeos.org
You'll need :
python -m venv venv
or
py -3.10 -m venv venv
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 https://stackoverflow.com/questions/40018405/cannot-open-include-file-io-h-no-such-file-or-directory
Install chocolatey
Open a Powershell console "Developer PowerShell for VS 2022" and activate your venv
venv\Scripts\activate.ps1
Install cmake
chocolatey install cmake
Partially apply procedure indicated here https://libgeos.org/usage/download/ :
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.)
msbuild.exe .\ALL_BUILD.vcxproj
msbuild.exe .\INSTALL.vcxproj
%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%
(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
💯
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
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:
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
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
orx64_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
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.
2 options:
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"
NB: the hash below may depend on your specific machine, and can be found in the start menu VS PowerShell for dev shortcut command details
Enter-VsDevShell 7c1743f6 -DevCmdArguments '-arch=x64 -no_logo'
(no logo is optional ...)
shortcut command
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}"
Description
I cannot install cartopy with pip, I see several solved issues reporting the same that are reportedly solved, but still it does not work for me. I would like to install it via pip, since then it is easy to set is as a requirement of my own package.
Code to reproduce
pip install cartopy
Traceback
Operating system
Windows 10
Cartopy version
0.17
pip list
Package Version Location
alabaster 0.7.12 appdirs 1.4.3 arrow 0.15.5 atomicwrites 1.3.0 attrs 19.3.0 Babel 2.8.0 backcall 0.1.0 bleach 3.1.0 bump2version 1.0.0 certifi 2019.11.28 cftime 1.1.0 chardet 3.0.4 Click 7.0 cloudpickle 1.3.0 colorama 0.4.3 coverage 5.0.3 cycler 0.10.0 Cython 0.29.15 DateTime 4.3 decorator 4.4.1 dfm-tools 0.4.3 c:\data\github\dfm_tools distlib 0.3.0 docutils 0.16 entrypoints 0.3 filelock 3.0.12 flake8 3.7.9 Flask 1.1.1 geos 0.2.2 idna 2.8 imagesize 1.2.0 importlib-metadata 1.5.0 ipykernel 5.1.4 ipython 7.12.0 ipython-genutils 0.2.0 itsdangerous 1.1.0 jedi 0.16.0 Jinja2 2.11.1 jupyter-client 5.3.4 jupyter-core 4.6.2 keyring 21.1.0 kiwisolver 1.1.0 lxml 4.5.0 MarkupSafe 1.1.1 matplotlib 3.1.3 mccabe 0.6.1 more-itertools 8.2.0 netCDF4 1.5.3 numpy 1.18.1 packaging 20.1 pandas 1.0.1 parso 0.6.1 pathtools 0.1.2 pickleshare 0.7.5 Pillow 7.0.0 pip 20.0.2 pkginfo 1.5.0.1 pluggy 0.13.1 proj 0.1.0 prompt-toolkit 3.0.3 py 1.8.1 pycodestyle 2.5.0 pyflakes 2.1.1 Pygments 2.5.2 pyparsing 2.4.6 PyQt5 5.14.1 PyQt5-sip 12.7.1 pytest 5.3.5 pytest-runner 5.2 python-dateutil 2.8.1 pytz 2019.3 pywin32 227 pywin32-ctypes 0.2.0 pyzmq 18.1.1 readme-renderer 24.0 requests 2.22.0 requests-toolbelt 0.9.1 scipy 1.4.1 setuptools 45.2.0.post20200210 Shapely 1.7.0 six 1.14.0 snowballstemmer 2.0.0 Sphinx 2.4.1 sphinxcontrib-applehelp 1.0.1 sphinxcontrib-devhelp 1.0.1 sphinxcontrib-htmlhelp 1.0.2 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.2 sphinxcontrib-serializinghtml 1.1.3 spyder-kernels 0.5.2 toml 0.10.0 tornado 6.0.3 tox 3.14.5 tqdm 4.42.1 traitlets 4.3.3 twine 3.1.1 urllib3 1.25.8 virtualenv 20.0.4 watchdog 0.10.2 wcwidth 0.1.8 webencodings 0.5.1 Werkzeug 1.0.0 wheel 0.34.2 wincertstore 0.2 zipp 3.0.0 zope.interface 4.7.1