这篇教程如何解决jupyter notebook无法导入自己安装的包写得很实用,希望能帮到您。
问题描述在使用jupyter notebook跑代码时,明明在虚拟环境(虚拟环境名字就是pytorch)中安装了pytorch,但是在导包的时候却报错,找不到对应的安装包 
jupyter notebook中输入运行如下代码,看看虚拟环境中的python库目录,发现里边根本没有包含我的虚拟环境所在路径 (我的虚拟环境路径是:C:/others/my_software/anaconda/envs/pytorch/Lib/site-packages )。 
解决办法



添加环境变量PYTHONPATH 和site-packages 安装包的路径 


再次查看虚拟环境中的python库目录,发现里包含我的虚拟环境所在路径 (我的虚拟环境路径是:C:/others/my_software/anaconda/envs/pytorch/Lib/site-packages )。 
此时就可以正常导包了 
总结以上为个人经验,希望能给大家一个参考,也希望大家多多支持wanshiok.com。 Jupyter Notebook如何导入python文件时的问题 使用pycharm进行绘图,图片无法显示的解决 |