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

在VS Code的Jupyter Notebook中导入scanpy时出现ImportError

解决ImportError: cannot import name 'colormaps' from 'matplotlib'问题

这个错误的核心原因是你的matplotlib版本过低——colormaps是matplotlib 3.7.0及以上版本才新增的API,当前环境里的matplotlib版本不满足scanpy的依赖要求。

具体解决步骤:

  • 检查当前matplotlib版本
    在VS Code终端执行以下命令查看版本:

    pip show matplotlib
    

    查看输出中的Version字段,确认是否低于3.7.0。

  • 升级matplotlib到兼容版本
    直接执行升级命令:

    pip install --upgrade matplotlib>=3.7.0
    

    若Python 3.8环境出现依赖冲突,可指定适配3.8的稳定版本:

    pip install matplotlib==3.7.1
    

    (注:matplotlib 3.7.x系列兼容Python 3.8,3.8及以上版本不再支持Python 3.8)

  • 验证修复效果
    重启Notebook内核后,重新执行单元格代码:

    import scanpy as sc
    

    无报错则说明问题已解决。

  • 可选:重新安装scanpy确保依赖匹配
    若升级matplotlib后仍有异常,可重新安装scanpy以拉取所有兼容依赖:

    pip install --force-reinstall scanpy
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 01:56:01