17

I am trying to change the interpreter path of my Jupyter notebook environment to the interpreter path I am using with PyCharm.

When I execute the following code with Jupyter notebook I am getting the python installation within the Anaconda main folder and not the one I am using with PyCharm.

import sys
print(sys.executable)

With which command I can change the path to the other python installation I am using with PyCharm?

PyPip
  • 171
  • 1
  • 1
  • 3

3 Answers3

23

I believe what you are looking for is how to change the Kernel you are running. If you go to the Kernel menu in Jupyter, you will see the option to change kernels.

enter image description here

If you want to add a new kernel from a conda environment, terminate jupyter, activate the environment you want to add a kernel for, and then run this command (requires conda install ipykernel -- thx @shad):

python -m ipykernel install --user --name <kernel_name> --display-name "<Name_to_display>"

Make sure to replace <kernel_name> and <Name_to_display> to the name of your environment. Also, this requires you to conda install ipykernel (thanks @shad).

Once you installed the kernel, you can change to it through the above menu and even through this code snippet from a Jupyter cell:

%%javascript
Jupyter.notebook.session.restart({kernel_name: '<kernel_name>'})
Daniel Schneider
  • 1,797
  • 7
  • 20
  • Amazing, thank you! I had to run this first: conda install ipykernel – shad Mar 25 '20 at 11:52
  • 4
    I don't understand what I have to put in , the path to the interpreter? – Argon888 Mar 24 '21 at 18:20
  • 2
    @user8635948 These instructions helped me: [link](https://queirozf.com/entries/jupyter-kernels-how-to-add-change-remove) - It seems you can choose both names arbitrarily. To get the python binary you want, run the command DanielSchneider posted from that binary. – dasWesen Mar 25 '21 at 14:38
  • 2
    What if my primary Jupyter is in E: and I want to use a Python interpreter from a venv in drive E:? – Nuclear03020704 Dec 17 '21 at 06:30
0

Activate first the env you want to use:

conda activate myenv

Then start jupyter afterwards:

jupyter notebook /path/to/your/dir
Hamza
  • 167
  • 2
  • 7
-1

You can also use the following:

conda activate base 

then check the location of the jupyter using

type jupyter

if it is located in

~/anaconda3/bin/jupyter

then you are good to go. After that, you can use the jupyter The one I use with my ssh-tunneling between my host and server machines is:

jupyter notebook --no-browser --port=1234
Dr Neo
  • 724
  • 6
  • 11