Jupyter notebook running a wrong Python kernel (Python 2 vs. Python 3)

I don’t know exactly what caused this and when, but I started to get an error while using Jupyter Notebook. The error was basically saying I can’t use Python 2 syntax even though I was in Python 2 Kernel.  I also couldn’t use packages installed in Python 2 environment such as Pandas.

jupyter notebook error
print syntax error. It requires me to use Python 3 syntax while I am in Python 2 kernel.

The printed system version tells me I am using Python 3.6 instead of Python 2.7.

jupyter notebook version check
Why Python 3 in Python 2 kernel?

After a quick research, I figured that I did not have right kernelspec for Python 2 and Python 3 and Jupyter Notebook automatically found and used Python 3 as a default (Source: GitHub discussion). As suggested here, I set up a new kernel for Python 2.

Minkyungs-MacBook-Pro:~ mkang$ sudo python2 -m ipykernel install
Installed kernelspec python2 in /usr/local/share/jupyter/kernels/python2

Now I have two kernels both for Python 2 and Python 3.
 In the file, I have language python for Python 2.
"display_name": "Python 2",
"language": "python",
"argv": [

My guess is that something went wrong while in the automatic migration from Ipython Notebook to Jupyter Notebook as explained here (http://jupyter.readthedocs.io/en/latest/migrating.html?highlight=kernelspec) but I am not 100% sure.

One thought on “Jupyter notebook running a wrong Python kernel (Python 2 vs. Python 3)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s