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

在Google Colab中降级Numpy至1.20.0以下版本时遇安装错误求助

降级Numpy至1.20以下时遇到metadata生成失败问题

我需要将Numpy版本降至1.18.0或1.20.0以下,但执行安装时出现如下错误:

Collecting numpy==1.18
  Using cached numpy-1.18.0.zip (5.4 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Preparing metadata (pyproject.toml) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

已尝试的操作

  • 检查当前版本,执行代码:
    import numpy as np
    print(np.__version__)
    
    结果显示版本为1.25;
  • 执行pip uninstall numpy,提示卸载成功;
  • 执行pip install numpy==1.18时出现上述错误,再次检查版本仍为1.25,尝试其他1.20以下版本结果一致。

解决方案

1. 适配旧版Numpy的pip版本安装

旧版Numpy(1.20.x及以下)与新版pip兼容性不佳,建议先降级pip到21.x版本再安装:

pip install pip==21.3.1
pip install numpy==1.18.0

2. 使用预编译wheel文件安装

跳过源码编译环节,直接安装预编译的wheel包:

  1. 执行python --version确认你的Python版本(如3.8、3.9),以及系统架构(32/64位)
  2. 下载对应版本的numpy-1.18.0 wheel文件
  3. 执行安装命令(替换路径和文件名):
pip install ./numpy-1.18.0-cp38-none-win_amd64.whl

3. 确认虚拟环境激活状态

如果使用虚拟环境,必须激活后再操作,避免全局环境的版本残留干扰:

# Linux/macOS激活虚拟环境
source venv/bin/activate
# Windows激活虚拟环境
venv\Scripts\activate

激活后重新执行卸载和安装命令。

4. 手动清理残留文件

卸载后若仍有Numpy残留,手动删除对应目录:

  1. 执行pip show numpy查看残留的安装路径(若卸载后仍能输出路径则说明有残留)
  2. 删除该路径下的Numpy相关文件夹
  3. 重新执行pip install numpy==1.18.0

内容的提问来源于stack exchange,提问作者Zahra

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 16:10:14