简体   繁体   中英

Change environment for Jupyter Notebook (Python3)

Whenever I install package using pip on my computer, they are not available in my Jupyter Notebooks. From what I figured out, they are not in the same environment. When I run

import sys
sys.executable

on the Notebook, I get

/Library/Developer/CommandLineTools/usr/bin/python3

while on the terminal I get

/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

What do I do to fix this? All answers I found online assume conda in installed, but I do not use conda. Ideally I would just change the default environment the Jupyter Notebook runs in but I can't figure out how...

EDIT

I tried adding the environment as suggested in another article by using the following code in terminal:

/Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -m ipykernel install --prefix=/Library/Developer/CommandLineTools/usr/bin/python3 --name 'Py3’

But it returns

quote>

Which I don't really understand.

You should change jupyter kernel via Kernel tab:

在此处输入图像描述

Use the explanation here if you want to add more kernels to jupyter: https://ipython.readthedocs.io/en/latest/install/kernel_install.html

Solved it by uninstalling Python 3 and then using homebrew and pyenv to install a new version in a more controlled manner and make it the system default. After a reboot it then worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM