jupyter not using version set by pyenv

In the mean time I have 90% solved it. From this article on the topic I found this pyenv which command had never tried before. So can see that there are two things that can be called.

(miniconda3-latest) cardamom@pegasus ~/Desktop/Project $ which jupyter
/home/cardamom/.pyenv/shims/jupyter

(miniconda3-latest) cardamom@pegasus ~/Desktop/Project $ pyenv which jupyter
/home/cardamom/.pyenv/versions/miniconda3-latest/bin/jupyter

Jupyter notebook seems to call the first one but if I enter the second path with the word 'notebook' after if, it launches fine and there is only one kernel available being the one with my pymysql module in it:

import sys
print (sys.version)

3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

Just need to work out how to call that directly without the whole path..

Update 15.05.17

Well, I fixed it, or helped it to fix itself -

rm -rf /home/cardamom/.pyenv/shims/jupyter*

Then closed and relaunched the terminal.

Surely wasn't the cleanest way, hope it hasn't broken something else, but now at least just running jupyter notebook is launching a notebook which contains the kernel active in my directory miniconda3-latest. The two which commands as per above are still returning the same thing, but now if I list the jupyter things in the first directory:

(miniconda3-latest) cardamom@pegasus ~/Desktop/Project $ ll /home/cardamom/.pyenv/shims/jupyter*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-bundlerextension*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-console*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-kernelspec*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-migrate*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-nbconvert*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-nbextension*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-notebook*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-qtconsole*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-run*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-serverextension*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-troubleshoot*
-rwxr-xr-x 1 cardamom cardamom 402 May 15 15:55 /home/cardamom/.pyenv/shims/jupyter-trust*
(miniconda3-latest) cardamom@pegasus ~/Desktop/Project $ 

...you can see that all those files just recreated themselves just a few minutes ago.


I found this gist which is pretty simple:

#!/bin/sh

if [ "$PYENV_VERSION" -ne "" ]
then
    name=`pyenv version-name`
    python=`pyenv which python`
else
    name=`basename "$VIRTUAL_ENV"`
    python="$VIRTUALENV/bin/python"
fi
jupyterdir=$(jupyter --data-dir)
kerneldir="${jupyterdir}/kernels/${name}"

echo "Installing jupyter kernel file $name for $python to $kerneldir ..."

pip install ipykernel
mkdir -p "$kerneldir"
cat > "$kerneldir"/kernel.json <<EOF
{
    "argv": [ "$python", "-m", "ipykernel", "-f", "{connection_file}" ],
    "display_name": "$name", 
    "language": "python"
}
EOF

cat "$kerneldir"/kernel.json 

Once I understood what was happening there, I went ahead and installed the pyenv plugin pyenv-jupyter-kernel and I like it very much.

Step 3 from this blog was pretty informative, though I didn't follow the steps. I read them and understood another perspective on that gist. It's always good to take in a few opinions before you blindly copy-pasta. There are a lot of outdated instructions out there!