Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make conda virtual environments persistent and available for tools such as Jupyter Notebook?

When a conda environment is activated in a shell window, the environment is only active in that window (i.e. not persistent). So when I navigate to the project location in another window, the "root" virtual environment is active.

Am I missing something or is this the intended behaviour?

How to give tools such as Jupyter Notebook access to the created environment?

like image 758
Greg Avatar asked Jul 09 '16 10:07

Greg


1 Answers

Register a (python) notebook kernel:

Let's suppose you have created a conda environment named jupyter-env35 with conda create -n jupyter-env35 python=3.5 and now want to use it in jupyter.

Installing and registering a python kernel in the environment will make it available over the graphical notebook interface.

To do so, first install the ipython kernel:

conda install -n jupyter-env35 ipykernel

Then activate the environment and register the kernel:

source activate jupyter-env35
ipython kernel install --user --name jupyter-env35

When you now fire up juypter, it will show jupyter-env35 as a kernel in the list of available kernels. If you select it, all packages installed into juypter-env35 will be available.

Unregister a notebook kernel:

If you want delete the kernel from the notebook interface, jupyter --data-dir, will print out jupyter's data directory.

Navigate to the printed folder, find the subfolder kernels and delete the folder with the name of your kernel (here jupyter-env35). After that the kernel will not show up in jupyter anymore.

like image 194
cel Avatar answered Oct 04 '22 23:10

cel