9

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?

cel
  • 30,017
  • 18
  • 97
  • 117
Greg
  • 8,175
  • 16
  • 72
  • 125
  • Yes, this is intended. Anaconda comes with a default environment. Whenever you start a new session, it will be activated by default. If you want to switch, you have to do so manually. If you want your enviroment availabe in the notebook, you have to install an ipython kernel into your environment. See my answer here for details how to do so. http://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebook/30492913#30492913 – cel Jul 09 '16 at 10:39

1 Answers1

15

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.

cel
  • 30,017
  • 18
  • 97
  • 117
  • So to be clear, when making a production install, the install happens in the root conda environment? – Greg Jul 09 '16 at 11:34
  • @Dave, yes, unless you create and activate your own environment, everything you install goes into the root environment. – cel Jul 09 '16 at 11:46
  • What I meant is for a webapp where cron executes scripts etc, the only way to have that working correctly is using the root environment? – Greg Jul 09 '16 at 11:48
  • @dave, you can write a short script that first activates an environment and then executes python commands and start that script with cron. – cel Jul 09 '16 at 14:40