In which conda environment is Jupyter executing?
Solution 1
Question 1: Find the current notebook's 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.
Question 2: Start Jupyter Notebook from within a different conda environment
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.
Solution 2
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.
Solution 3
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
Solution 4
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.
Solution 5
You can also switch environments in Anaconda Navigator, install Jupiter and run it.
Related videos on Youtube
RockScience
Updated on January 15, 2022Comments
-
RockScience over 2 years
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?
-
cel almost 8 yearsinstall a separate ipython kernel in every environment you want to use in jupyter notebook. This way it does not matter which jupyter instance you are starting.
-
Thomas K almost 8 yearsDocs on installing kernels for environments. To see which conda env a notebook is running in, you can check
sys.executable
. -
jkdev over 7 yearsIt's easier if you use the package
nb_conda_kernels
. Related question/answer: Using both Python 2.x and Python 3.x in IPython Notebook -
Nathan over 4 yearsPlease also see this great article. Briefly, it talks very clearly about the difference between
jupyter
's "kernel" python environment and the shell's python environment you launchjupyter notebook [notebook_name].ipynb
from. -
Rich Lysakowski PhD about 3 yearsQuestion 1 simplest answer is to type " !conda info " or "import sys; print(sys.executable)" into a current notebook cell or at the command prompt. For Question 2 follow the simplest answer below.
-
Redoman about 2 years@Nathan since you must have written your comment right after finishing reading the article you linked I'd have appreciated if you also summarized what those differences are
-
Dror over 7 yearsWhat should I do if I don't have the
Conda
tab? -
jkdev over 7 years@Dror Make sure jupyter notebook is running from within a conda environment. Check where your jupyter is located by running
which jupyter
on the command line. -
Dror over 7 years
which jupyter
returns/Users/name/anaconda/envs/myEnv/bin/jupyter
and I don't get theConda
tab nor environment name in[]
. Myjupyter
version is 4.2.0 -
Dror over 7 yearsIt seems like the missing piece is stuartmumford.uk/blog/jupyter-notebook-and-conda.html Thanks @chinnychinchin (stackoverflow.com/a/39900046/671013)
-
BigBoy1337 over 7 yearshmm this doesn't seem to work for me... I cannot import modules even though I see my condo environment as default in the environment list and am running my default conda env
-
Rishabh Agrahari about 7 yearsIn my case, after
conda install jupyter
, I deactivated env, then ranjupyter notebook
, then I got my env listed in the dropdown of 'new'. -
Ken Myers almost 7 yearsThank you! I tried everything above this and this was the only thing that worked short of deleting and remaking the environment
-
Rishabh Agrahari over 6 yearsNote: to reflect the changes, please restart the conda environment.
-
Damon Yuan over 6 yearsthis is the right way to bring the notebook to the environment
-
Harsh over 6 years@BigBoy1337 ink's answer
conda install nb_conda
seems to be the most straightforward way to get to the state described in this answer. -
taper over 6 yearsNote: In addition, you would need
Jupyter
(or perhapsipykernel
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. -
vizyourdata about 6 yearsThis worked to finally get my theano environment working from jupyter. Thanks!
-
Jack M almost 6 years"source is not recognized as an internal or external command, operable program or batch file"
-
Royi almost 6 years@JackM,
source
is needed under Linux / macOS. On Windows just useactivate
. -
Royi almost 6 yearsCan one have different configuration file of
Jupyter
per eachconda
envioronment? -
TayTay over 5 years@RockScience, consider switching this to be the accepted answer.
-
Huanfa Chen over 5 yearsVery helpful. Solved the issue.
-
Bersan over 5 yearsYes, this was the right answer. nb_conda alone didn't work.
-
Sincole Brans over 5 yearsif it throws "kernel Error" we need to install users for the kernels,add "python -m ipykernel install --user"
-
Neveroldmilk over 5 yearsGreat solution! But it is difficult to delete these manually added ipykernel environment.
-
Lukas almost 5 years
import sys; print(sys.executable)
was the only thing that worked for me -
Martin Thøgersen almost 5 yearsShould nb_conda be installed in base env, target env, or both? Please extend the answer, thanks.
-
MattR over 4 yearsSometimes
nb_conda
doesn't play nice with someconda
/pip
installed libraries. When setting up a new environment I encourage you to installnb_conda
first then install your other libraries -
emeralddove over 4 yearsVery helpful. I was about to remove anaconda directory and start all over again. you saved me weeks of work that could have lost in another few minutes. thanks a ton.
-
jtiscione over 4 yearsIf you have any other packages installed nb_conda will insist on downgrading them to three year old versions. Make sure to run conda update --all if it clobbers your workspace.
-
OverFlow Police over 4 yearswhy everything in this solution/notebook looks different from my Jupyter notebook? on home page, I do not have Conda, on top right mine does not say Python[env_name], when I click on New, there is no Python[env_name] I have installed Earth Engine module which works in terminal, but not on Jupyter!
-
OverFlow Police over 4 yearsHere is a link to a screenshot of my Python: ibb.co/g6JNh5Q
-
Bonson almost 4 yearsThank you. This was required for me to finally see the specific environment in the Kernels tab when Jupyter Notebooks is opened.
-
seeker_after_truth almost 4 yearsWhen I go to my Jupyter homescreen and click "new", my only options for notebook are Python 3, even though I have created several different environments in Anaconda navigator. How did you get the other options?
-
user75252 over 3 yearsdo we need to install jupyter notebook in the new environment?
-
YoussefDir over 3 years@MartinThøgersen Anaconda Prompt was in the target env when I ran
conda install nb_conda
but I feel it's irrelevant. -
Ramon over 3 yearsReferring to question 1, what is the path for this at Jupyter Lab?
-
Alex W over 3 yearsTo delete start a terminal in jupyter and run
jupyter kernelspec uninstall [env_name]
-
Rich Lysakowski PhD about 3 yearsThis is the simplest and easiest answer for part 1 of the OP's questions.
-
Rich Lysakowski PhD about 3 yearsYou should create the environment directly from the Anaconda Desktop GUI Environment. This answer gives unintended and unwanted side effects from using pip to modify a conda environment. You should not mix pip and conda commands within the same environment. See anaconda.com/blog/using-pip-in-a-conda-environment for more information.
-
Rich Lysakowski PhD about 3 yearsThis is the best answer. nb_conda is fraught with compatibility problems and brings a lot of detritus into the base environment.
-
apoorv020 almost 3 yearsI had to change
~/.local/share/jupyter/kernels/<myenv>/kernel.json
as well. -
Jakinduria over 2 yearsI can confirm that this solution also worked for me on Windows. The file that needs to be edited should be found in
C:\\Users\\username\\AppData\\Roaming\\jupyter\\kernels\\myenv
, in which you need to change the path of thepython.exe
file to that found in your environment, which should probably be as such:C:\\Users\\username\\anaconda3\\envs\\myenv\\python.exe
. -
hbstha123 over 2 yearsWorked for me. Thanks!