Jupyter running wrong python kernel
See original GitHub issueHi everyone, I want to report that Jupyter is loading the wrong Kernel
My machine is a Debian Testing,
Linux 4.9.0-3-amd64 #1 SMP Debian 4.9.30-1 (2017-06-04) x86_64 GNU/Linux
Python2.7 is installed by default, Python3 was installed from repositories, but I’m not sure if it comes by default with the system too. Jupyter and Ipython where installed via Pip (Pip was installed from the repositories)
Module Versions
Installed via pip with dependencies
pip install -U jupyter ipython
pip3 install -U jupyter ipython
So far, the versions installed are,
- Jupyter version 4.3.0 (PIP2 and PIP3)
- Python 3.5.3 from repos
- Python 2.7.13 from repos
- Ipython 5.4.1 (PIP2)
- Ipython3 6.1.0 (PIP3)
Proceeded to install the corresponding kernels as root with the commands,
ipython kernel install
ipython3 kernel install
Which seemed to work since Jupyter recognizes both kernels
And at the location /usr/local/share/jupyter/kernels
there’s this tree architecture
With the relevant contents,
$ cat python2/kernel.json
{
"display_name": "Python 2",
"language": "python",
"argv": [
"/usr/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
]
}
$ cat python3/kernel.json
{
"display_name": "Python 3",
"argv": [
"/usr/bin/python3",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"language": "python"
}
I try to program with Python3 standard since 2.7 is old, so Installed a module I wanted to use by means of pip3 install module_name
. The module worked with python3 console and Ipython3 console, but when I tried to implement the code inside a Jupyter notebook (with kernel Python3) and I got an error telling that the module wasn’t available. After being unable to solve the problem I installed the module with pip2 and suddenly it was available at the Jupyter notebook (with kernel Python3) so I performed a simple check of the version of the running kernel under Jupyter,
As you can see, it says that the kernel is Python3, but the call to sys.version
(from the module sys
) still shows that the running kernel is Python2.7. I don’t know what’s going on, even resetted Jupyther’s configuration with jupyter notebook --generate-config
and the issue remains unsolved, that’s why I decided to post here.
On the other hand, calling the deprecated form ipython3 notebook
produces the desired result,
Wath am I missing?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:34
- Comments:47 (11 by maintainers)
Top GitHub Comments
@takluyver off course, as you thought there was an override of the kernels. The output of
jupyter kernelspec list
was,The kernel for python3 located in
/home/damejia/.local/share/jupyter/kernels/python3
was incorrectly configured. Thekernel.json
read,So it called the wrong python version (
python
points to Python 2.7 in my machine). I just removed the/home/damejia/.local/share/jupyter/kernels/
path and nowjupyter kernelspec list
shows,And under a Python3 kernel in Jupyter the output of,
baheves as expected,
I’m not sure why this happened, I’ve been using Jupyther for about a year without problems so far. I hope this thread can help anyone. I guess It’s closed 👍
I also encountered a similar error. Jupyter notebook installation in my Ubuntu 17.04 cloud machine had issues selecting the right kernel. This is what I did to solve this issue.
Step 1: Install all the necessary dependencies: For Python2: $sudo apt-get install python-setuptools python-dev build-essential $sudo easy_install pip
$python2 -m pip --version
$python2 -m pip install ipykernel $sudo python2 -m ipykernel install --user $pip install -U jupyter ipython
For Python3: $sudo apt-get install python3-setuptools python3-dev build-essential $sudo apt-get install python3-pip
$python3 -m pip --version
$sudo python3 -m pip install ipykernel $sudo python3 -m ipykernel install --user $sudo pip3 install -U jupyter ipython
Step 2: Find the python executable locations for each version of Python and available kernels for Jupyter:
For Python2: $python
For Python3: $python3
To get the list of available kernels:
$jupyter kernelspec list
The output for me was: Available kernels: python2 /home/info/.local/share/jupyter/kernels/python2 python3 /home/info/.local/share/jupyter/kernels/python3
Step 3: Update the kernel.json file with the correct location pointers to python executable
For Python2: $sudo nano /usr/local/share/jupyter/kernels/python2/kernel.json
Eg:
{ “display_name”: “Python 2”, “language”: “python”, “argv”: [ “/usr/bin/python”,
“-m”, “ipykernel_launcher”, “-f”, “{connection_file}” ] }
For Python3: $sudo nano /usr/local/share/jupyter/kernels/python3/kernel.json
{ “display_name”: “Python 3”, “language”: “python”, “argv”: [ “/usr/bin/python3”,
“-m”, “ipykernel_launcher”, “-f”, “{connection_file}” ] }
Step 4: Restart Jupyter and toggle kernels to see if python versions are selected correctly in the back-end.