While using new Python 2 Kernel for Jupyter Notebook installed last time (Previous post), I found I cannot use Python libraries I had in my Python 2 in my local. Apparently, Python 2 environment used in the new Python 2 Kernel was not the same Python 2 environment that I have been using so far.
To resolve this issue and avoid confusion, I separated python environments using Conda and tie a specific environment to each Jupyter Kernel.
The first step is obviously creating a python environment (Later I will explain how I did it but here is the basic tutorial for this). But unfortunately, running Jupyter notebook from an environment does not mean the notebook will run in the same environment. It uses the default Conda environment instead of specific environment you are running the notebook from.
I had to install nb_conda, which is an extension to provide Conda environment and an access to the associated packages from within Jupyter (Ref). Detailed info can be found here on GitHub.
Run Jupyter Notebook after activating your environment. You can see now your Conda environment can be found in the kernel list. You can also check which kernel you are running the current notebook with from the top right.
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.
The printed system version tells me I am using Python 3.6 instead of Python 2.7.
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.