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
>>> 

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

<think>嗯,用户在使用PyCharm时运行pip install schedule报错,需要解决这个问题。首先,我需要回忆常见的pip安装报错原因。可能的问题包括网络连接问题、pip版本过旧、包名称错误、权限问题、环境配置问题或者PyCharm本身的配置错误。 首先,用户是否拼写正确?schedule这个包确实存在,所以可能不是包名错误。接下来考虑网络问题,尤其是国内用户可能因为默认源速度慢或不可访问导致超时。可以建议更换镜像源,比如清华源或阿里源,使用命令pip install schedule -i https://pypi.tuna.tsinghua.edu.cn/simple。 然后,检查pip版本是否过旧,升级pip试试:python -m pip install --upgrade pip。如果用户使用的是Python3,可能需要用pip3代替pip,特别是系统同时安装了Python23的情况。 权限问题也可能导致安装失败,尤其是在Linux或macOS上。可以建议加上sudo(但Windows不需要),或者使用--user选项安装到用户目录:pip install schedule --user。 另外,PyCharm的项目可能使用了虚拟环境,需要确认终端是否激活了正确的环境。有时候PyCharm的终端没有自动激活虚拟环境,导致包安装到全局环境中。用户应该检查PyCharm的设置,确保在项目对应的虚拟环境中安装。 还有可能Python解释器路径配置错误。用户需要检查PyCharm中的解释器设置,路径是否正确,是否有写入权限。 如果以上方法都不行,可能需要查看具体的错误信息。常见的错误如连接超时、SSL错误、依赖缺失等。根据错误提示具体解决,比如SSL错误可以尝试使用信任的镜像源:pip install schedule --trusted-host pypi.tuna.tsinghua.edu.cn -i https://pypi.tuna.tsinghua.edu.cn/simple。 另外,有时候防火墙或代理设置也会阻止pip访问网络,需要检查网络设置是否有问题。如果用户在公司或学校网络,可能需要配置代理。 最后,确保用户安装的是正确的包。虽然schedule是一个常用的调度库,但有时候可能有其他同名包或拼写错误。可以建议用户到PyPI官网确认包的存在和正确名称。 总结下来,解决步骤应该是先检查网络和镜像源,然后升级pip,确认环境和权限,再根据具体错误信息调整策略。如果用户能提供具体的错误信息,可以更精准地解决问题。</think>在PyCharm中使用`pip install schedule`报错时,可以按照以下步骤排查解决: --- ### **1. 确认包名正确性** - **schedule**是Python中常用的定时任务库,但需确保拼写无误。可前往PyPI官网验证:[https://pypi.org/project/schedule/](https://pypi.org/project/schedule/) --- ### **2. 检查网络问题(尤其是国内用户)** #### 方案一:使用国内镜像源加速 ```bash pip install schedule -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 其他常用镜像源: - 阿里云:`https://mirrors.aliyun.com/pypi/simple` - 豆瓣:`https://pypi.doubanio.com/simple` #### 方案二:信任镜像源(解决SSL验证问题) ```bash pip install schedule --trusted-host pypi.tuna.tsinghua.edu.cn -i https://pypi.tuna.tsinghua.edu.cn/simple ``` --- ### **3. 升级pip工具** ```bash python -m pip install --upgrade pip ``` - 如果使用Python3,可能需要替换为`pip3`: ```bash pip3 install schedule ``` --- ### **4. 检查PyCharm环境配置** - **确认PyCharm使用的Python解释器**: 1. 打开PyCharm → `File` → `Settings` → `Project: <项目名>` → `Python Interpreter` 2. 检查顶部选择的解释器路径是否正确(避免安装到全局环境而非虚拟环境)。 - **重启PyCharm**:部分配置更改后需重启生效。 --- ### **5. 权限问题处理** - **Windows**:以管理员身份运行PyCharm或CMD。 - **Linux/macOS**:尝试添加`sudo`或使用`--user`安装到用户目录: ```bash sudo pip install schedule # 或 pip install schedule --user ``` --- ### **6. 查看具体错误信息** - **根据报错内容精准解决**: - **超时错误**(`TimeoutError`):更换镜像源或检查网络。 - **依赖缺失**(如需要C++编译环境):安装Microsoft C++ Build Tools。 - **权限拒绝**(Permission Denied):使用`--user`或提升权限。 --- ### **7. 验证安装结果** - 在PyCharm的Python控制台中输入: ```python import schedule print(schedule.__version__) ``` - 若无报错且输出版本号,说明安装成功。 --- ### **常见问题示例** #### 问题1:`Could not find a version that satisfies the requirement schedule` - **原因**:镜像源未同步最新包。 - **解决**:更换镜像源或添加`--default-timeout=100`延长超时时间。 #### 问题2:`SSLError(SSLCertVerificationError)` - **解决**:添加`--trusted-host`参数或使用HTTP源(不推荐)。 --- 通过以上步骤,90%以上的安装问题可以解决。如果仍报错,建议提供完整的错误信息以便进一步分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

szZack

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

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

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

打赏作者

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

抵扣说明:

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

余额充值