IPython is an interactive notebook that is accessed from your browser. It is extremely useful because it is designed with code sharing in mind, supports up to 49 different languages/versions of languages, and has “cells”, or blocks of code that are interpreted one at a time (or all at once). Another reason to use IPython is to easily switch between Python versions, or kernels. In this post I’ll show how to install both major versions of Python and access them in an IPython notebook. If you haven’t installed either version of Python, go here and follow the instructions to perform a first time install (the method should work for 2.7 as well as 3+). And if you haven’t installed IPython yet, no sweat (from the command line):
pip install ipython
Installing the other version of Python
Once you’ve installed both versions of Python, open the command prompt as administrator and navigate to the respective directory, for example “cd C:\Python27\Scripts” (or Python3 if you’re trying to add Python3) then type these commands:
python -m pip install ipykernel
You may need additional c compilers and get an error message saying “error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27”. Follow the link, download and install.
Now enter this command into the command prompt:
python -m ipykernel install --user
There. Your second Python install should be associated with IPython notebook. Launch IPython from the command line with:
And copy the url it outputs into your browser. You should be able to select both versions of Python now like so:
Remember, any modules that you have installed for one version, you’ll need to also install for the other version(s).
To install multiple kernels for other virtualenvs or conda environments, see readthedocs.io.
IPython is frequently a tool of choice in many data analysis projects. If you are just getting started learning data analysis with Python , see this summary of quality free learning resources. Cheers!