已经安好了anaconda,并在prompt里创建好了pytorch虚拟环境(虚拟环境名称为torchtest),可是在jupyter notebook里import torch仍然会报错没有torch这个模块。
于是就碰到了在jupyter notebook里使用虚拟环境的问题,这里记录一下配置方法。
为了让Jupyter Notebook支持虚拟运行环境,需要在Anaconda prompt里安装一个插件:
conda install nb_conda
然后在prompt里继续安装:
#1、安装ipykernel:
conda install ipykernel
#2、为虚拟环境下创建kernel文件:
conda install -n 环境名称 ipykernel
#3、将环境写入notebook的kernel中:
python -m ipykernel install --user --name 环境名称 --display-name "显示的名称"
再重新打开jupyter notebook在kernel-change kernel里就能看到自己创建的虚拟环境torchtest了。
![914790274537d855d489365acbac3195.png](https://i-blog.csdnimg.cn/blog_migrate/b7c73ef120cc00397f2635202d64e2c8.jpeg)
By the way,我安装的jupyter主题是chesterish。
参考资料:
1、如何在Jupyter Notebook中使用Python虚拟环境?
2、启动jupyter notebook配置虚拟环境
3、 Aanconda+虚拟环境+jupyter notebook配置