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.
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
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
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
I don't really know the definition and relationship between kernel and conda env, but I beleive we can set a kernel for each env.
I got a problem similar to you: I clean my data in data_cleaning.ipynb
under env_without_lgb
. However, I have lightgbm
installed under env_lightgbm
. So, I want to switch kernel/env from env_without_lgb
to env_lightgbm
, which we can use Kernel -> Change Kernel
:
If there is not a kernel you want, create a kernel under the right env according to this guide. For me, I only have a Pure Python 3 kernel
and R kernel
at first and then I create a kernel under env_lightgbm
. At last, we can switch kernel when we editing our code.
However, I still can not figure out the relationship between kernel and env.
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'