Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

python - Change Interpreter in Jupyter notebook

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>'})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...