ModuleNotFoundError: No module named 'cartopy' when import SkewT from metpy.plots under Python3

ModuleNotFoundError: No module named 'cartopy' when import SkewT from metpy.plots under Python3

当尝试将 SkewT 导入我在 Mac (Mojave 10.14.6) 上的 python3 代码时:

from metpy.plots import SkewT

我收到错误:

ModuleNotFoundError: No module named 'cartopy'

pip3 install cartopy 给出输出

Collecting cartopy
  Downloading https://files.pythonhosted.org/packages/e5/92/fe8838fa8158931906dfc4f16c5c1436b3dd2daf83592645b179581403ad/Cartopy-0.17.0.tar.gz (8.9MB)
     |████████████████████████████████| 8.9MB 616kB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Complete output from command /usr/local/opt/python/bin/python3.7 /usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpj50b1vfe:
  ERROR: setup.py:171: 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), ))
  Proj 4.9.0 must be installed.
  ----------------------------------------
ERROR: Command "/usr/local/opt/python/bin/python3.7 /usr/local/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpj50b1vfe" failed with error code 1 in /private/tmp/pip-install-b5cu8485/cartopy

首先,我尝试安装 Proj 和 geos,但 pip3 只列出了 proj 的版本 0.1.0 和 geos 的 0.2.2。在我深入这个兔子洞之前,我想看看是否还有其他人遇到过这个问题。谢谢!

你用 Conda 吗?解决此问题的最简单方法是通过 conda 安装 CartoPy(或以这种方式安装 MetPy),以便同时下载所有正确的依赖项:conda install -c conda-forge cartopyconda install -c conda-forge metpy。 Pip 并没有把所有这些都放在一起,所以导致这个问题被提出来。

谢谢。没有conda,我也能够完成这个(更痛苦的)安装:

    - brew install geos
    - brew install proj
    - pip3 install cython
    - pip3 install git+https://github.com/SciTools/cartopy.git@master 
(see http://louistiao.me/posts/installing-cartopy-on-mac-osx-1011/)

所以看起来 MetPy 0.10 意外地获得了对 CartoPy 的硬依赖,这是我们没有真正计划的。您可以跟踪我们对 here.

的解决方案

不幸的是,CartoPy 依赖于许多不可通过 pip 安装的已编译库。您最好的选择是查看 CartoPy's install instructions。如果您使用的是 Anaconda 或 Canopy,这些发行版都有可用的预构建 CartoPy 包。

解决此问题的一个方法是安装 MetPy 0.9:

pip install metpy==0.9