shapely与GeoPandas的安装-Python版本是3.10.0

我的Python版本是3.10.0。因为需要做一个判断地理空间栅格图层与矢量图层是否相交的功能,需要用到两个模块:
import geopandas as gpd
import shapely.geometry as sg
阿西吧,这两个玩意好难安装,花费了我好长时间,我日。所以做个记录,希望能帮助有需要的人。
(1)shapely的安装
在本地pip命令安装shapely的时候,提示:
Could not find geos-config executable. Either append the path to geos-config to PATH or manually provide the include_dirs, library_dirs, libraries and other link args for compiling against a GEOS version >=3.5.
ERROR: Cython is required to build shapely from source.
这个错误是由于shapely依赖GEOS(Geometry Engine, Open Source)库,并且需要Cython来编译shapely。我是在官网下载的最新版本GEOS 0.2.3(官网上好像就只有这个版本)。Cython在下面安装GeoPandas时候解决了。

安装好GEOS和Cython后遇到报错,提示安装的 Shapely 版本与你的 Python 版本不兼容。我优重新下载了对应的python310版本的Shapely 1.8.2版本,就没有报错了,我下载地址是https://www.lfd.uci.edu/~gohlke/pythonlibs/。这个版本去官网下载也有。

Shapely 1.8 需要:Python >=3.6,GEOS >=3.3。很奇怪,我在官网下载的最新版本GEOS 0.2.3好像版本低,应该不符合要求才对。我猜官网上唯一的这个版本GEOS 0.2.3是升级版吧,能用就行。此外,上面的下载地址https://www.lfd.uci.edu/~gohlke/pythonlibs/也有高版本的geos,但我没去下。

题外话:我一开始安装的最新版的Shapely 2.0 需要:Python >=3.7,GEOS >=3.5,NumPy >=1.14,多了个NumPy >=1.14(这个版本我安装后用不了,可能是当时NumPy 忘记更新到 >=1.14)

总结:需要正确安装对应python版本的Shapely 要求的GEOS 和Cython。

(2)GeoPandas的安装
GeoPandas集成了Shapely、Fiona和PyProj等地理信息处理库,允许你加载、分析和操作地理空间数据。你可以在GeoDataFrame中存储矢量数据(如地图边界、点、多边形等),并执行空间查询和分析。GeoPandas包我好像是在官网下载的geopandas 0.11.0,反正这个包下载好麻烦,pip安装,镜像安装都不成功,最后稀里糊涂下了这个版本。当时官网最新版本是0.14.0.,但我下了好像装不了。

(1)试图安装geopandas时候,遇到提示:
ERROR: Could not find a version that satisfies the requirement pandas>=1.4.0 (from geopandas) (from versions: none)
ERROR: No matching distribution found for pandas>=1.4.0

Geopandas需要一个较新版本的Pandas(至少1.4.0),因此你需要升级Pandas

(2)当我试图安装pandas时,提示
ERROR: Could not find a version that satisfies the requirement numpy>=1.22.4; python_version < “3.11” (from pandas) (from versions: none)
ERROR: No matching distribution found for numpy>=1.22.4; python_version < “3.11”

这里的意思是Pandas依赖于NumPy,并且需要一个较新版本的NumPy(至少1.22.4)

(3)当我试图安装NumPy到最新版本,提示
numpy.distutils is deprecated since NumPy 1.23.0, as a result
of the deprecation of distutils itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use setuptools < 60.0 for those Python versions.
For more details, see:
https://numpy.org/devdocs/reference/distutils_status_migration.html

import numpy.distutils.command.sdist

Note: if you need reliable uninstall behavior, then install
with pip instead of using setup.py install:

  • pip install . (from a git repo or downloaded source
    release)
  • pip install numpy (last NumPy release on PyPI)

Traceback (most recent call last):
File “C:\Users\ASUS\Desktop\numpy-1.26.1\setup.py”, line 321, in generate_cython
import Cython
ModuleNotFoundError: No module named ‘Cython’

这个错误是因为在尝试安装NumPy时,它需要Cython作为依赖项来构建一些部分,但系统中似乎没有安装Cython。

我试图安装cython,但是提示
ERROR: Cannot unpack file C:\Users\ASUS\AppData\Local\Temp\pip-unpack-l_edp_kk\simple.html (downloaded from C:\Users\ASUS\AppData\Local\Temp\pip-req-build-opay37_l, content-type: text/html); cannot detect archive format
ERROR: Cannot determine archive format of C:\Users\ASUS\AppData\Local\Temp\pip-req-build-opay37_l
这个错误看起来像是下载Cython包时出现了问题。后来尝试pip下载,镜像下载,官网下载包都不能正确安装。没办法,最后在https://www.lfd.uci.edu/~gohlke/pythonlibs/里下载符合我版本的cython解决了。

(4)可以安装最新版numpy了,安装好了numpy。现在我想安装pandas,但是提示
ERROR: Could not find a version that satisfies the requirement pytz>=2020.1 (from pandas) (from versions: none)
ERROR: No matching distribution found for pytz>=2020.1
这个错误提示表明你的系统中缺少满足pytz版本要求的包。pytz是Python中用于处理时区信息的包。这个我直接pip安装好了。

**总结:GeoPandas需要对应版本的Pandas,而pandas需要对应版本的NumPy,而NumPy时需要对应版本的Cython。解决完以上问题后,安装Pandas时需要对应版本的pytz。这是我的电脑遇到的问题,可能大家遇到的情况不一样,所以需要安装的东西和顺序不一定与我一样。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值