Using Ipython

I started to move along with using python 3, I want my python shell for to be working properly. As many of us must be aware, Python Shell is not really a very interactive prompt and most of the time, while I am working with Python, I tend to install Ipython as an alternative to work more flexibly with Python Shell.

When I downloaded and installed python3. I do not get ipython, this needs to be installed separately.

The pip3 install ipython3 didn’t came of much help.

As, I am having multiple versions of python running on to my system, one is the native python version 2.7.11 which by default came with my OS, other python version 3.5.1 which I had explicity downloaded for using python3.

Googling around did helped much either, and the solution was pretty simple for implementation so I am documenting here in case anyone needs a quick help.

$ which ipython
$ which python3

cp /usr/local/bin/ipython /usr/local/bin/ipython3

edit the ipython3 file.


# -*- coding: utf-8 -*-
import re
import sys

from IPython import start_ipython

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])

Change the shebang which is #!/usr/local/bin/python to #!/usr/local/bin/python3

Save the file.

run ipython3, I am assuming /usr/local/bin is in your system path.

$ ipython
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44) 
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]:

What we basically did, was copied the original ipython file which was being used by python version 2 and ensured that to work with python3 by changing its shebang line, which tells ipython to use the desired python version. In case, if you do not already have ipython installed then pip install ipython will just work, post your python 3 installation.

Though this is a quick hack, but really not an ideal solution.

Try and use virtual environment in case of multiple python installations.

%d bloggers like this: