1

I have 2 conda environments installed:
- env1: base environment where jupyter-notebook is installed and started from
- env2: project environment with ipykernel installed I manually added kernelspecs for the 2 environments following this guide.

Everything works fine. sys.executable in 2 kernels show separate, correct paths. But for terminal commands (i.e. !which python), no matter which kernel I'm running in the environment defaults to env1.

Is there any way to have the notebook automatically change this to the kernel's environment?

P.S. I already tried installing nb_conda, nb_conda_kernels

Tin Ng
  • 1,174
  • 1
  • 8
  • 14
  • I'm not sure if I understand the question correctly, but maybe this Q&A helps? https://stackoverflow.com/questions/58068818/how-to-use-jupyter-notebooks-in-a-conda-environment – lumbric Sep 23 '19 at 19:57

2 Answers2

1

install nb_conda and nb_conda_kernels into your base.

conda install nb_conda nb_conda_kernels -n env1

This should give you the ability to change kernel in jupyter, and use the env2 kernel.

emmet02
  • 932
  • 5
  • 8
  • This does not work. In fact I already had these 2 packages from before. – Tin Ng Dec 07 '18 at 03:51
  • Can you try listing kernelspecs? jupyter kernelspec list – emmet02 Dec 07 '18 at 09:41
  • python3 /home/ec2-user/miniconda3/envs/airflow3/lib/python3.6/site-p ackages/ipykernel/resources | airflow3 /home/ec2-user/.local/share/jupyter/kernels/airflow3 | data_interface /home/ec2-user/.local/share/jupyter/kernels/data_interface – Tin Ng Dec 07 '18 at 09:52
0

I would install jupyter notebook in the base env (not env1, not env2) Then install nb_conda_kernels in the base

in env1 and env2, install ipykernel in env1 and env2, run this:

python -m ipykernel install --user --name env1 --display-name "env1 env"

Check this out for more info: New Conda environment with latest Python Version for Jupyter Notebook

J R
  • 436
  • 3
  • 7