一、准备工作
Miniconda的安装请参考我的另一篇博客文章:
安装好Miniconda之后,就可以准备下一步了。
二、安装Jupyter Notebook
由于咱们想在多个虚拟环境中都可以使用Jupyter,所以这里将 Jupyter 单独安装在一个环境中,对其他环境进行隔离。若安装在某个特定的环境中的话,则运行 Jupyter Notebook 需要进入当时安装时的虚拟环境,那就比较麻烦了。
第一步:创建Jupyter自己的虚拟环境
conda create -n jupyter
第二步:激活jupyter虚拟环境
bash
conda activate jupyter
如下图:

第三步:在刚才创建的jupyter虚拟环境中,安装Jupyter Notebook
bash
conda install jupyter notebook
安装完毕:

三、让Jupyter Notebook可以作用于所有虚拟环境
为了让咱们刚刚在Miniconda的jupyter虚拟环境中安装的Jupyter Notebook可以很方便地管理Miniconda下的各个虚拟环境。
我在我的另一篇博客中介绍了Miniconda安装PyTorch,大家可以参考创建一个PyTorch的虚拟环境:
好了,现在假设您已经安装好了PyTorch的虚拟环境(我这里PyTorch的虚拟环境名称是zachen),这样就可以在jupyter
环境中安装nb_conda_kernels
包,并在其他需要用到的环境中(我这里是PyTorch的虚拟环境zachen)安装ipykernel
包,示例如下:
1.在安装有Jupyter Notebook的虚拟环境中安装nb_conda_kernels
包:
bash
conda activate jupyter
conda install nb_conda_kernels

- 打开您的另外一个虚拟环境(我这里是上文提到的zachen),安装
ipykernel
包:
bash
conda activate zachen
conda install ipykernel

- 在j
upyter
环境下运行Jupyter Notebook :
bash
jupyter notebook

此时,您会发现Jupyter Notebook已经打开了。

写在最后
最后多罗嗦一句,在jupyter虚拟环境中,可以去到您的工作目录,我这里是:
bash
cd zachen
您在哪个目录下执行jupyter notebook,它就会在哪个目录下打开,非常方便。