Ubuntu下pip install cartopy报错完整可行解决方案

Ubuntu下pip install cartopy报错解决方法

一、Cartopy介绍

  • Cartopy介绍
    Cartopy是一个用于地理空间数据处理的Python包,用于生成地图和其他地理空间数据分析。

  • 工作原理:
    利用强大的project .4,NumPy和Shapely库,并包括一个构建在Matplotlib之上的编程接口,用于创建发布质量地图。

  • 主要特性
    定义投影、点线面之间的转换等。

二、解决方案

1.错误信息

使用pip安装Cartopy库时,出现报错:

  <string>:117: UserWarning: Unable to determine GEOS version. Ensure you have 3.7.2 or later installed, or installation may fail.
  Proj 8.0.0 must be installed.

安装命令:

pip install cartopy

详细错误信息如下:

pip install cartopy

Collecting cartopy
  Downloading Cartopy-0.20.3.tar.gz (10.8 MB)
     |████████████████████████████████| 10.8 MB 1.7 MB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmpb3nj3t_y get_requires_for_build_wheel /tmp/tmpfdg6t0pj
       cwd: /tmp/pip-install-qapq224f/cartopy
  Complete output (2 lines):
  <string>:117: UserWarning: Unable to determine GEOS version. Ensure you have 3.7.2 or later installed, or installation may fail.
  Proj 8.0.0 must be installed.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 /tmp/tmpb3nj3t_y get_requires_for_build_wheel /tmp/tmpfdg6t0pj Check the logs for full command output.

2.环境

  • Ubuntu 20.04 LTS
  • python 3.8.10
    【注】
    1、安装 cartopy 时,python版本必须大于等于3.8
    2、Ubuntu 必须是 20.04 或以上版本
    szZack的博客

3.解决方法

  • 3.1安装依赖

    apt-get update
    apt-get install libgeos-dev  libgeos++-dev proj-bin libproj-dev -y
    apt-get install sqlite3
    apt-get update -y && apt-get install -y  apt-utils autoconf automake libxmu-dev libpcap-dev curl  gcc gdb  ipython3  python-tk
    apt install pkg-config
    apt-get install libtiff-dev
    apt install -y libghc-curl-dev
    

    szZack的博客

  • 3.2安装proj-8.2.1

    wget https://download.osgeo.org/proj/proj-8.2.1.tar.gz
    tar -xf proj-8.2.1.tar.gz
    cd proj-8.2.1
    ./configure && make && make install
    

    修改环境变量 :

    vi  ~/.bashrc
    # 在末尾输入内容:
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/proj-8.2.1/src/.libs
    

    【注】退出终端,重启进入终端才会生效

  • 3.3安装 cartopy

    pip install cartopy
    

4.成功解决

pip install cartopy

Collecting cartopy
  Using cached Cartopy-0.20.3.tar.gz (10.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting pyshp>=2.1
  Downloading pyshp-2.3.1-py2.py3-none-any.whl (46 kB)
     |████████████████████████████████| 46 kB 595 kB/s
Requirement already satisfied: pyproj>=3.0.0 in /usr/local/lib/python3.8/dist-packages (from cartopy) (3.3.1)
Requirement already satisfied: shapely>=1.6.4 in /usr/local/lib/python3.8/dist-packages (from cartopy) (1.8.4)
Requirement already satisfied: matplotlib>=3.1 in /usr/local/lib/python3.8/dist-packages (from cartopy) (3.5.3)
Requirement already satisfied: numpy>=1.18 in /usr/local/lib/python3.8/dist-packages (from cartopy) (1.23.2)
Requirement already satisfied: certifi in /usr/local/lib/python3.8/dist-packages (from pyproj>=3.0.0->cartopy) (2022.6.15)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.1->cartopy) (0.11.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.1->cartopy) (1.4.4)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.1->cartopy) (21.3)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.1->cartopy) (9.2.0)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.1->cartopy) (2.8.2)
Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.1->cartopy) (3.0.9)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.1->cartopy) (4.36.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.8/dist-packages (from python-dateutil>=2.7->matplotlib>=3.1->cartopy) (1.16.0)
Building wheels for collected packages: cartopy
  Building wheel for cartopy (PEP 517) ... done
  Created wheel for cartopy: filename=Cartopy-0.20.3-cp38-cp38-linux_x86_64.whl size=11004824 sha256=d8f825952ce1756fc34092a8e2319a65bf6a020bbd12c54ead36d1f212303270
  Stored in directory: /root/.cache/pip/wheels/0a/88/c1/b220aefe265631e8ed2212b818f96db51258683079a6d442f3
Successfully built cartopy
Installing collected packages: pyshp, cartopy
Successfully installed cartopy-0.20.3 pyshp-2.3.1

出现上面的信息说明 cartopy 安装成功
szZack的博客

5.测试cartopy

# python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cartopy
>>> 

没有报错则说明安装成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

szZack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值