How to get iPython to use Python 2 instead of Python 3

I have both Python 2.7 and 3.5 installed. If I run the script from the command line using python , it uses Python 2.7, but if I started iPython, it uses Python 3:

 kurt@kurt-ThinkPad:~$ python -V Python 2.7.12 kurt@kurt-ThinkPad:~$ ipython Python 3.5.2 (default, Sep 10 2016, 08:21:44) Type "copyright", "credits" or "license" for more information. IPython 5.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython features. %quickref -> Quick reference. help -> Python own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: 

Is there a way to launch iPython so that it uses Python 2? (I am using Ubuntu LTS 16.04).

+4
ipython
Nov 04 '16 at 9:52
source share
4 answers

After ipython reads the wrong version of python , in /usr/local/bin/ipython I just changed

 #!/usr/bin/python3 

in the first line

 #!/usr/bin/python 

and Python 2 became the standard version used by iPython:

 kurt@kurt-ThinkPad:~$ ipython Python 2.7.12 (default, Jul 1 2016, 15:12:24) Type "copyright", "credits" or "license" for more information. IPython 2.4.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython features. %quickref -> Quick reference. help -> Python own help system. object? -> Details about 'object', use 'object??' for extra details. 
+3
Nov 04 '16 at 10:41
source share

Less intrusive solution (since my solution below does not need to modify any library files), this problem

 python2.7 -m IPython notebook 

therefore the general team

{{python-you-want-ipython-to-use}} -m IPython notebook

Why will this work?

Because if you see an ipython script (/ usr / local / bin / ipython), it is like a python script in itself and it has shebang (#! / Usr / bin / python3), so ipython is not a standalone binary but it gets life due to some python. Thus, in order for the ipython script itself to need some python to run it, so you run the ipython module directly using any python of your choice, instead of letting / usr / local / bin / ipython solve it for you, and fix the problem "of what python ipython uses.

+3
Jun 15 '17 at 2:18
source share

IPython 6.0+ now does not support Python 2.6, 2.7, 3.0, 3.1, or 3.2. If using Python 2.7, please install the long-term version of IPython 5.x support.

Starting with IPython 6.0, Python 3.3 and higher is required.

+1
02 Feb '18 at 11:29
source share

The next cel second solution (for non-Anaconda users) is to use both Python 2.x and Python 3.x in the IPython Notebook , I set up two virtual environments for Python 2 and Python 3 and installed iPython separately for each.

0
Nov 04 '16 at 10:06
source share



All Articles