Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch environment on Jupyter notebook for new notebook?

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.

like image 529
rgaut Avatar asked Nov 08 '17 23:11

rgaut


People also ask

How do I change the environment of a Jupyter Notebook?

You can also create new environments from within Jupyter Notebook (home screen, Conda tab, and then click the plus sign). And you can create a notebook in any environment you want. Select the "Files" tab on the home screen and click the "New" dropdown menu, and in that menu select a Python environment from the list.

Do I need to install Jupyter Notebook for each environment?

Jupyter Notebook can easily be installed using conda. Our plan is to only install it in the base environment, and then just switch between sub-environments to avoid setting up Jupyter Lab in each environment.

How do you switch between environments in Anaconda?

If you want to switch to another environment you could simply type: conda activate myenv within the base environment. Now when you deactivate myenv it will go back to base environment. When you are within an environment, the packages within that environment can be accessible.


2 Answers

Installing the nb_conda_kernels package as suggested by user @jcb91 worked for me. I did have to install it both in my root (base) environment as well as the virtual environment with which I wanted to use it. To do this, run the following in the Anaconda prompt (in your base environment):

conda install nb_conda_kernels

Then, activate your virtual environment (in the code below named 'myenv') and install the nb_conda_kernels package there as well. You can do this by running in the Anaconda prompt:

conda activate myenv
conda install nb_conda_kernels

You now should be able to switch to your different environment using:

Kernel -> Change Kernel
like image 111
Anne Avatar answered Sep 18 '22 12:09

Anne


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
like image 40
jcb91 Avatar answered Sep 22 '22 12:09

jcb91