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

已安装Matplotlib且可运行,但仍提示“No module named matplotlib”求助

解决Matplotlib已安装但PyCharm仍报错的问题

1. 核对PyCharm的Python解释器配置

  • 打开PyCharm,依次进入 File > Settings > Project: [你的项目名] > Python Interpreter
  • 查看当前使用的解释器路径,然后在终端用对应解释器的pip命令检查是否真的安装了Matplotlib:
    • 比如解释器是python3.10,就运行 python3.10 -m pip list,查看列表中是否有Matplotlib
    • 如果没找到,用该解释器的pip重新安装:python3.10 -m pip install matplotlib

2. 清空PyCharm缓存

  • 点击 File > Invalidate Caches...
  • 勾选 Clear file system cache and local history,然后点击 Invalidate and Restart
  • 重启PyCharm后,检查错误提示和代码补全是否恢复正常

3. 检查项目虚拟环境(如果使用了的话)

  • 如果项目用了虚拟环境,先在终端激活它:Windows系统执行venv\Scripts\activate,Linux/macOS执行source venv/bin/activate
  • 激活后运行 pip install matplotlib
  • 返回PyCharm,确认解释器选择的是这个虚拟环境的Python版本

4. 手动添加Matplotlib安装路径(极端情况)

  • 先查询Matplotlib的安装路径:终端运行 pip show matplotlib,查看输出中的Location字段
  • 在PyCharm中进入 File > Settings > Project: [你的项目名] > Python Interpreter > 右上角齿轮图标 > Show All
  • 选中当前解释器,点击 Show paths for the selected interpreter,再点击加号,把刚才查到的Location路径添加进去,最后重启PyCharm

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 03:10:16