Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

jupyter notebook - Changing Python Executable

I'm pretty new to programming, and very new to doing so in a UNIX environment, so please bear with me.

When I run

import sys
sys.executable

in my Python 3 console, the output is

usrinpython3

and I'm able to import whatever libraries I've installed with pip3, no problem. When I do so in my Jupyter Notebook running a Python 3 kernel, the output is

usrinpython

and the libraries that I've installed with pip3 are inaccessible to me. What can I do to fix it so Jupyter is executing Python from the right place so I can use anything I've installed for Python 3 with pip3?

Thank you!

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Short

You need to register your Python kernel with Jupyter, for it to find the "right" Python

Long

Jupyter is meant to work with multiple kernels, and languages; it is common for some users to have tens of kernels, many can be the same language, with small differences. You usually need to "tell" jupyter about these kernels, it is often referred to as "Installing a kernelspec". In your case you need to:

  • Install IPython & ipykernel for your Python 3
  • Using the ipykernel you just installed: install the kernelspec.

You'll find instruction on above link, a few tip though:

  • You can always safely replace python by /full/path/to/python if you are unsure.
  • when using pip, you can always replace pip (or pip3) by /full/path/to/python -m pip to use the pip linked to the python you want.
  • If you are tempted to use sudo, don't. People telling you to use sudo get issues after a few month when their linux distribution need to be updated – unless you really know what you're doing.

Once you've registered the Python kernel with Jupyter, it should just appear in the menus. You may need to refresh your browser though.

Enjoy !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...