I have jupyter/anaconda/python3.5.
How can I know which conda environment is my jupyter notebook running on?
How can I launch jupyter from a new conda environment?
Join Stack Overflow to learn, share knowledge, and build your career.
I have jupyter/anaconda/python3.5.
How can I know which conda environment is my jupyter notebook running on?
How can I launch jupyter from a new conda environment?
Open the notebook in Jupyter Notebooks and look in the upper right corner of the screen.
It should say, for example, "Python [env_name]" if the language is Python and it's using an environment called env_name.
Activate a conda environment in your terminal using source activate <environment name>
before you run jupyter notebook
. This sets the default environment for Jupyter Notebooks. Otherwise, the [Root] environment is the default.
You can also create new environments from within Jupyter Notebook (home screen, Conda tab, and then click the plus sign).
And you can create a notebook in any environment you want. Select the "Files" tab on the home screen and click the "New" dropdown menu, and in that menu select a Python environment from the list.
which jupyter
returns /Users/name/anaconda/envs/myEnv/bin/jupyter
and I don't get the Conda
tab nor environment name in []
. My jupyter
version is 4.2.0
– Dror
Sep 29 '16 at 14:27
conda install jupyter
, I deactivated env, then ran jupyter notebook
, then I got my env listed in the dropdown of 'new'.
– Rishabh Agrahari
Feb 28 '17 at 18:49
conda install nb_conda
seems to be the most straightforward way to get to the state described in this answer.
– Harsh
Dec 8 '17 at 14:28
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.
Jupyter
(or perhaps ipykernel
according to the answer by rakesh) installed in that environment. Otherwise Jupyter can recognise that environment, but it cannot create new notebook in that environment.
– taper
Dec 29 '17 at 16:47
nb_conda
doesn't play nice with some conda
/pip
installed libraries. When setting up a new environment I encourage you to install nb_conda
first then install your other libraries
– MattR
Aug 16 '19 at 19:50
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
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.
You can also switch environments in Anaconda Navigator, install Jupiter and run it.
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:
conda activate MyEnv
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.
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'
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.
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
For more info, check out this link and this previous Stack Overflow question..
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
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
from platform import python_version print(python_version())
then just jupyter notebook
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.
sys.executable
. – Thomas K May 7 '16 at 11:13nb_conda_kernels
. Related question/answer: Using both Python 2.x and Python 3.x in IPython Notebook – jkdev Aug 22 '16 at 2:01jupyter
's "kernel" python environment and the shell's python environment you launchjupyter notebook [notebook_name].ipynb
from. – Nathan Aug 22 '19 at 8:16