How to switch environment on Jupyter notebook for

2019-04-08 15:40发布

问题:

I have an instance with various environment and some notebooks are compatible with different environment for e.g. notebook1 is for MXNet and notebook2 is for Tensorflow.

How do I jump to new environment when I move from notebook1 to notebook2? I tried doing that but this doesn't quite work with Jupyter notebook? Any suggestion?

So I need to do it from conda environment but looks like jupyter notebook UI doesn't respect (calls right activation function) to set the path.

回答1:

You could use the nb_conda_kernels package, which provides a separate jupyter kernel for each conda environment, along with the appropriate code to handle their setup. This makes switching conda environment as simple as switching jupyter kernel (e.g. from the kernel menu), which I find very convenient. You can get it from the conda-forge channel, using

conda install -c conda-forge nb_conda_kernels


回答2:

When you start a jupyter notebook within an environment, it will only have access to the modules installed in that particular enviroment. If you need two specific environments for two different notebooks, you will need to start a jupyter notebook within the two environments separately.

If you are using anaconda, you would do the following in a terminal:

source activate MXNET
jupyter notebook

Then in a second terminal:

 source activate Tensorflow
 jupyter notebook


回答3:

Along with this package I think also need to change the ~/.jupyter/jupyter_notebook_config.py file with following config

c.NotebookApp.kernel_spec_manager_class = 'environment_kernels.EnvironmentKernelSpecManager'