Shapely安装失败主因是GEOS二进制依赖缺失、架构不匹配或PyPI无对应whl文件;推荐用pip install shapely --pre(预编译版自带GEOS)、指定版本如shapely==2.0.1,或换用64位Python。

pip install shapely 这条命令在多数现代 Python 环境(如 Python 3.9–3.12 + 64位 Windows/macOS/Linux)下能直接成功,但**它经常失败——不是命令写错了,而是背后缺 GEOS 二进制依赖、架构不匹配或 PyPI 没提供对应 whl 文件**。别急着重试,先看下面这几个关键点。
Windows 上 pip install shapely 报 DLL load failed
这是最典型的错误,提示类似 ImportError: DLL load failed while importing _geos: 找不到指定的模块。,本质是 Shapely 找不到 GEOS 动态库。
- 优先用
pip install shapely --pre:--pre允许安装预发布版,这些版本已内嵌 GEOS DLL,跳过系统级依赖 - 避免手动下载 DLL 放入
PATH或Python\DLLs:容易版本错配,且每次升级 Python 都要重配 - 如果公司网络拦截 PyPI,加国内镜像源:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple shapely --pre
pip install shapely 提示 Could not find a version that satisfies
说明 PyPI 没有为你当前环境(Python 版本 + 系统架构 + 位数)打包好的 wheel 文件,比如你用的是 Python 3.13a 或 32位 Python。
调用百度文档解析API,支持18+格式,提取文本、表格、版面分析、OCR识别及RAG文档分块。适用于文档解析、文本/表格提取、结构分析、扫描件处理。触发词:文档解析、PDF解析、Word解析、表格提取、OCR、文档分析、提取文本、文档结构、扫描识别。
- 查清你的环境:
python -c "import platform; print(platform.architecture(), platform.machine())" - Python 3.11+ 推荐锁死版本:
pip install shapely==2.0.1(2.0.x 起全面支持新 Python,并自带 GEOS) - 32位 Python 用户必须找 32位编译的包,但官方已停止提供;建议换用 64位 Python,否则只能从源码编译(需 Visual Studio Build Tools + GEOS SDK)
安装后 import shapely 成功但调用 .buffer() 报错
常见于旧版 Shapely(
- 检查版本:
python -c "import shapely; print(shapely.__version__)",低于1.8建议升级 - 清干净再装:
pip uninstall shapely -y && pip install shapely==2.0.1 --no-cache-dir --pre - 验证是否真可用:
python -c "from shapely.geometry import Point; print(Point(0,0).buffer(1).area)",输出应接近3.14159
为什么不用 conda install shapely?
conda 确实能绕过很多 pip 的 GEOS 问题,但它默认走 conda-forge 渠道,会连带升级 numpy/scipy 等,可能破坏现有环境。
- 仅当项目已全栈用 conda 管理时才推荐:
conda install -c conda-forge shapely - 混合使用 pip + conda 容易引发
ImportError: cannot import name 'Geometry'类错误,因为两套 ABI 不兼容 - 虚拟环境仍是底线:
python -m venv shp-env && shp-env\Scripts\activate && pip install shapely --pre
shapely 不是纯 Python 包——它强依赖 GEOS 的二进制形态,而这个形态在不同系统、Python 版本、位数之间并不通用。哪怕只差一个 patch 版本(如 3.12.3 vs 3.12.4),PyPI 也可能没上传对应 wheel。所以看到报错别硬刚,先用 --pre 和指定版本试试。

















