15

I'm using Anaconda to manage both Python and Jupyter. That is:

>> which python
>> /home/.../software/anaconda3/bin/python

and

>> which jupyter
>> /home/.../software/anaconda3/bin/jupyter

But Jupyter's python kernel seems to be pointing to a system version of Python rather than my local version through Anaconda, since the sys.path is different in a Jupyter Python 3 notebook. Also, jupyter kernelspec list gives the following:

Available kernels:
  ir         /usr/local/share/jupyter/kernels/ir
  matlab     /usr/local/share/jupyter/kernels/matlab
  python3    /usr/local/share/jupyter/kernels/python3

This doesn't seem altogether surprising since the docs say in section 1.5.5:

By default, kernel specs will go in a system-wide location (e.g. /usr/local/share/jupyter/kernels). If doing a --user install, the kernel specs will go in the JUPYTER_DATA_DIR location.

For personal sanity and organization, I want the version of Python that I use in the command line to be the same that is accessed in Jupyter. As a result, I think that what I should do is change my jupyter kernelspec list for python3 so that it points to my desired Anaconda python version, i.e. /home/.../software/anaconda3/bin/python. My questions are: 1) is that indeed the best solution for my stated preferences, and 2) how do I actually change my jupyter kernelspec entry for python3? Not sure if this will come up, but I don't want to be using virtual environments--I want the default to be same version of Python across both the command line and Jupyter.

Community
  • 1
  • 1
itf
  • 559
  • 1
  • 3
  • 15

2 Answers2

8

I ended up reposting this to the Jupyter Github issues page, and was recommended to delete /usr/local/share/jupyter/kernels/python3. This allows Jupyter to find a default Python kernel using the same Python running Jupyter itself (i.e. Anaconda), and this worked for me.

You can find my post on Jupyter's Github page as well as an explanation for why the above solution works here.

itf
  • 559
  • 1
  • 3
  • 15
2

1) Jupyter kernels in /usr/local/ are indeed a global install. But I do not see why it couldn't be linked to your anaconda python3 interpreter.

2) To explicitly link your anaconda interpreter to your jupyter install you can run :

pip install ipykernel
python -m ipykernel install --prefix=/usr/local/ --name "anaconda_kernel"

for a global install, or change /usr/local/ if you want a per user install. A doc is specially set for anaconda here

If you combine it with jupyter kernelspec remove python3 beforehand, you can then reset your anaconda kernel as default to be sure.

MCMZL
  • 1,078
  • 9
  • 21
  • So the tip in 2) creates another python kernel linked to anaconda named "anaconda_kernel?" I tried that for my user account, and got the following: `Installed kernelspec anaconda_kernel in /tmp/share/jupyter/kernels/python3/.../share/jupyter/kernels/anaconda_kernel` but `jupyter kernelspec list` shows the same kernels as before. Also, the link in your answer does not go anywhere. – itf Oct 03 '17 at 22:53
  • Sorry I edited the link. maybe you have to adapt `--prefix=/usr/local/` you have several paths possible mentioned in the link. Ex : you might try `~/.local/share` on Ubuntu for a per user install. – MCMZL Oct 04 '17 at 14:13