求助:PyCharm中使用Jupyter插件无法导入Python库模块
PyCharm Jupyter插件无法导入Python库的解决办法
遇到的错误示例:
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[1], line 1 ----> 1 import numpy as np ModuleNotFoundError: No module named 'numpy'
核对Jupyter内核与项目解释器是否一致
- 打开PyCharm的
File > Settings > Project: [你的项目名] > Python Interpreter,复制当前项目的解释器路径 - 在Jupyter notebook单元格里执行
import sys; print(sys.executable),对比输出路径和上面的是否相同 - 路径不符的话,点击Jupyter界面右上角的内核名称,选择
Change Kernel,切换到项目对应的解释器内核;如果没有对应内核,在PyCharm终端执行python -m ipykernel install --user --name=项目专属内核,重启Jupyter后选择新内核
- 打开PyCharm的
确认库安装在当前解释器环境
- 在PyCharm的Python Interpreter界面,查看已安装包列表,检查numpy、pandas是否存在
- 未安装就点击
+搜索安装;已安装但报错,选中包点击右上角的✓重新安装 - 也可以直接在PyCharm终端执行
pip install numpy pandas(确保终端左侧显示项目虚拟环境标识,比如(venv))
修复Jupyter插件关联
- 打开
File > Settings > Plugins,找到Jupyter插件,先禁用再启用,重启PyCharm - 终端执行
pip install --upgrade ipykernel jupyter,更新相关依赖
- 打开
清理缓存
- 清除PyCharm缓存:
File > Invalidate Caches...,勾选Clear file system cache and local history,点击Invalidate and Restart - 删除项目目录下的
.ipynb_checkpoints文件夹,重新打开notebook
- 清除PyCharm缓存:
内容的提问来源于stack exchange,提问作者TsuuN
相关产品推荐
相关产品推荐

