3

I am pretty new to Python so please excuse me if this seems basic.

I am using JupyterLab and finding that although it uses Python 3, it is using a different installation to that used by my terminal. If I run sys.executable in terminal I get

'/usr/local/opt/python/bin/python3.7'

In JupyterLab I get

'/usr/local/Cellar/jupyterlab/1.2.4/libexec/bin/python3.7'

In practice this means that if I pip3 install package in terminal, it won't be available in JupyterLab. I can do something like %pip install package or /usr/local/Cellar/jupyterlab/1.2.4/libexec/bin/python3.7 -m pip install package in a cell in a notebook for e.g. but I feel this is probably not best practice to be using indefinitely and it would be better if these were in sync.

Running jupyter kernelspec list gives me

Available kernels:

python3 /usr/local/Cellar/jupyterlab/1.2.4/libexec/lib/python3.7/site-packages/ipykernel/resources

Various answers and issues like this suggest editing the kernel.json but there isn't a file of this name in that folder.

I've also seen answers that involve creating virtual environments, which is something I'll probably be exploring but I'd like to deal with the issue at a more foundational level.

Can anybody explain what I am missing?

EDIT:

This is a duplicate of the question linked in the comments. Will look to close it but thought it might be useful making clear what steps I took because it takes a few clicks to get there.

In terminal:

pip3 install ipython
python3 -m pip install ipykernel
python3 -m ipykernel install --user

Then if I run jupyter kernelspec list I get

/Users/stodem01/Library/Jupyter/kernels/python3

which contains a kernel.json with a path that matches that in terminal.

Community
  • 1
  • 1
Jaccar
  • 1,720
  • 17
  • 46
  • Does this answer your question? https://stackoverflow.com/questions/46270435/changing-python-executable – nima Jan 27 '20 at 12:43
  • 1
    Thanks nima, I've gone through the answer there and it seems to work! Adding detail of what I did to the question but will vote to close as a duplicate. – Jaccar Jan 27 '20 at 14:14
  • Does this answer your question? [Changing Python Executable](https://stackoverflow.com/questions/46270435/changing-python-executable) – Jaccar Jan 27 '20 at 14:22

0 Answers0