You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

虚拟环境依赖冲突问题:安装spaCy时numpy版本兼容矛盾及升级困境

虚拟环境依赖冲突问题:安装spaCy时numpy版本兼容矛盾及升级困境

看起来你现在陷入了一个典型的Python虚拟环境依赖版本死循环——装spaCy需要高版本numpy,但升级numpy后又搞崩了一堆常用数据分析库,我来给你捋捋几个可行的解决思路:

你的当前问题场景

1. 安装spaCy时触发的依赖错误

你尝试安装spaCy时,收到了blis和thinc这两个底层依赖的版本冲突提示,它们明确要求numpy版本落在 >=2.0.0,<3.0.0 区间,但你当前环境里的numpy还是1.23.5,不满足要求:

blis 1.0.1 has requirement numpy<3.0.0,>=2.0.0, but you have numpy 1.23.5.
thinc 8.3.2 has requirement numpy<2.1.0,>=2.0.0; python_version >= "3.9", but you have numpy 1.23.5.

2. 升级numpy后引发的新冲突

当你试图升级numpy到2.0.2来解决spaCy的问题时,又发现一堆日常高频使用的数据分析库(比如matplotlib、pandas这些)还只支持<2.0版本的numpy,直接触发了一串兼容性报错:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
contourpy 1.2.0 requires numpy<2.0,>=1.20, but you have numpy 2.0.2 which is incompatible.
matplotlib 3.7.3 requires numpy<2,>=1.20, but you have numpy 2.0.2 which is incompatible.
pandas 2.2.0 requires numpy<2,>=1.23.2; python_version == "3.11", but you have numpy 2.0.2 which is incompatible.
pyarrow 15.0.0 requires numpy<2,>=1.16.6, but you have numpy 2.0.2 which is incompatible.
pywavelets 1.5.0 requires numpy<2.0,>=1.22.4, but you have numpy 2.0.2 which is incompatible.
scikit-learn 1.4.1.post1 requires numpy<2.0,>=1.19.5, but you have numpy 2.0.2 which is incompatible.
scipy 1.12.0 requires numpy<1.29.0,>=1.22.4, but you have numpy 2.0.2 which is incompatible.
statsmodels 0.14.1 requires numpy<2,>=1.18, but you have numpy 2.0.2 which is incompatible.

可行的解决办法

方案1:给spaCy单独创建隔离的虚拟环境(最推荐)

这是最省心且零风险的方案,毕竟你当前主环境里有大量依赖numpy1.x的工具,强行改动容易引发更多问题。你可以用Python自带的venv或者conda新建一个干净环境,专门用来运行spaCy:

  • 用venv的操作命令示例:
    # 创建名为spacy-env的虚拟环境
    python -m venv spacy-env
    # Windows系统激活环境
    spacy-env\Scripts\activate
    # Mac/Linux系统激活环境
    source spacy-env/bin/activate
    # 直接安装spaCy,pip会自动匹配符合要求的numpy及相关依赖
    pip install spacy
    

之后主环境继续用numpy1.x跑数据分析,新环境用numpy2.x跑spaCy,两个环境完全隔离,彻底解决冲突。

方案2:降级spaCy到兼容numpy1.23.5的版本

如果你一定要在当前主环境中安装spaCy,可以找一个不需要numpy2.x的旧版本。比如指定一个较低的spaCy版本安装,大概率能兼容numpy1.x:

pip install spacy<3.7  # 版本号可根据实际测试调整

你也可以先跳过依赖检查安装spaCy本体,再手动安装兼容numpy1.23.5的blis和thinc版本,但这种方式容易触发其他隐性依赖问题,不如直接指定spaCy版本来得省心。

方案3:逐步升级所有依赖到支持numpy2.x的版本

这个方案能从根本上统一环境版本,但操作起来最折腾。你需要把所有报冲突的库升级到支持numpy2.x的最新稳定版,再安装spaCy:

# 先批量升级冲突的依赖库
pip install --upgrade matplotlib pandas scikit-learn scipy contourpy pyarrow pywavelets statsmodels
# 再安装spaCy
pip install spacy

注意:部分库可能还未推出支持numpy2.x的稳定版,升级前建议先查一下对应库的官方文档确认兼容性,避免升级后出现新的问题。

备注:内容来源于stack exchange,提问作者MUHAMMAD KASHIF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 16:23:06