[ipython] In which conda environment is Jupyter executing?

I have jupyter/anaconda/python3.5.

  1. How can I know which conda environment is my jupyter notebook running on?

  2. How can I launch jupyter from a new conda environment?

This question is related to ipython anaconda jupyter jupyter-notebook

The answer is


To check on which environment your notebook is running type the following commands in the notebook shell

import sys
print(sys.executable)

To launch the notebook in a new environment deactivate that environment first. Create a conda environment and then install the ipykernel. Activate that environment. Install jupyter on that environment.

conda create --name {envname}
conda install ipykernel --name {envname}
python -m ipykernel install --prefix=C:/anaconda/envs/{envname} --name {envname}
activate envname
pip install jupyter

In your case path "C:/anaconda/envs/{envname}" could be different, check accordingly. After following all steps, launch notebook and do step 1 run the following in shell.

sys.executable

This should show: Anaconda/envs/envname


which environment is jupyter executing:

import sys
print(sys.executable)

create kernel for jupyter notebook

source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
source activate other-env
python -m ipykernel install --user --name other-env --display-name "Python (other-env)"

http://ipython.readthedocs.io/en/stable/install/kernel_install.html#kernel-install


I have tried every method mentioned above and nothing worked, except installing jupyter in the new environment.

to activate the new environment conda activate new_env replace 'new_env' with your environment name.

next install jupyter 'pip install jupyter'

you can also install jupyter by going to anaconda navigator and selecting the right environment, and installing jupyter notebook from Home tab


Question 1: How can I know which conda environment is my jupyter notebook running on?

  • Launch your Anaconda Prompt and run the command conda env list to list all the available conda environments.

    Anaconda Prompt Screenshot

    You can clearly see that I've two different conda environments installed on my PC, with my currently active environment being root(Python 2.7), indicated by the asterisk(*) symbol ahead of the path.

Question 2: How can I launch jupyter from a new conda environment?

  • Now, to launch the desired conda environment, simply run activate <environment name>. In this case, activate py36

    enter image description here

For more info, check out this link and this previous Stack Overflow question..


Because none of the answers above worked for me, I write here the solution that finally solved my problem on Ubuntu. My problem was:
I did the following steps:

  1. Activate my environment: conda activate MyEnv
  2. Start jupyter notebook:jupyter notebook

Although MyEnv was active in the terminal and had an asterix when writing conda env list, but jupyter notebook was started with the base environment. Installing nb_conda and ipykernel didn't solve the problem for me either. Additionally, the conda tab wasn't appearing in jupyter notebook and also clicking on the kernels or going to the menu Kernel->Change Kernel didn't show the kernel MyEnv.
Solution was: install the jupyter_environment_kernel in MyEnv environment:

pip install environment_kernels

After that when starting jupyter notebook, it is started with the right environment. You can also switch between environments without stopping the kernel, by going to the menu Kernel->Change Kernel and selecting the desired kernel.


You can also switch environments in Anaconda Navigator, install Jupiter and run it. Anaconda Navigator


The following commands will add the env in the jupyter notebook directly.

conda create --name test_env
conda activate test_env
conda install -c anaconda ipykernel
python -m ipykernel install --user --name=test_env

Now It should say, "Python [test_env]" if the language is Python and it's using an environment called test_env.


to show which conda env a notebook is using just type in a cell:

!conda info

if you have grep, a more direct way:

!conda info | grep 'active env'

  1. For checking on Which Python your Jupyter Notebook is running try executig this code.

from platform import python_version print(python_version())

  1. In order to run jupyter notebook from your environment activate MYenv and install jupyter notebook using command pip install jupyter notebook

then just jupyter notebook


If the above ans doesn't work then try running conda install ipykernel in new env and then run jupyter notebook from any env, you will be able to see or switch between those kernels.


Adding to the above answers, you can also use

!which python

Type this in a cell and this will show the path of the environment. I'm not sure of the reason, but in my installation, there is no segregation of environments in the notebook, but on activating the environment and launching jupyter notebook, the path used is the python installed in the environment.


As mentioned in the comments, conda support for jupyter notebooks is needed to switch kernels. Seems like this support is now available through conda itself (rather than relying on pip). http://docs.continuum.io/anaconda/user-guide/tasks/use-jupyter-notebook-extensions/

conda install nb_conda

which brings three other handy extensions in addition to Notebook Conda Kernels.


Examples related to ipython

How to increase image size of pandas.DataFrame.plot in jupyter notebook? Importing .py files in Google Colab Selection with .loc in python IOPub data rate exceeded in Jupyter notebook (when viewing image) Purpose of "%matplotlib inline" Installing a pip package from within a Jupyter Notebook not working convert json ipython notebook(.ipynb) to .py file In which conda environment is Jupyter executing? How to make inline plots in Jupyter Notebook larger? %matplotlib line magic causes SyntaxError in Python script

Examples related to anaconda

Upgrade to python 3.8 using conda Updating Anaconda fails: Environment Not Writable Error Jupyter Notebook not saving: '_xsrf' argument missing from post Conda version pip install -r requirements.txt --target ./lib How to check python anaconda version installed on Windows 10 PC? Anaconda / Python: Change Anaconda Prompt User Path How to access Anaconda command prompt in Windows 10 (64-bit) Conda activate not working? update to python 3.7 using anaconda Tensorflow import error: No module named 'tensorflow'

Examples related to jupyter

How to increase image size of pandas.DataFrame.plot in jupyter notebook? What is the difference between Jupyter Notebook and JupyterLab? Removing Conda environment How to open local file on Jupyter? Jupyter notebook not running code. Stuck on In [*] Can I run Keras model on gpu? IOPub data rate exceeded in Jupyter notebook (when viewing image) How to execute a * .PY file from a * .IPYNB file on the Jupyter notebook? how to make a new line in a jupyter markdown cell Running Jupyter via command line on Windows

Examples related to jupyter-notebook

How to prevent Google Colab from disconnecting? Jupyter Notebook not saving: '_xsrf' argument missing from post How do I install Python packages in Google's Colab? What is the difference between Jupyter Notebook and JupyterLab? Importing .py files in Google Colab Display all dataframe columns in a Jupyter Python Notebook How to open local file on Jupyter? how to open Jupyter notebook in chrome on windows Change the Theme in Jupyter Notebook? Jupyter notebook not running code. Stuck on In [*]