Search code examples
pythonmacospython-3.xpython-2.7macos-sierra

How to change the python interpreter for ipython on mac?


I have python libraries in the following folders on my mac

  • /usr/local/lib/python2.7/site-packages/
  • /usr/local/lib/python3.6/site-packages/

and, the corresponding binaries as the following files

  • /usr/local/bin/python2.7
  • /usr/local/bin/python3.6

But, the ipython binary is in /usr/local/Cellar/ipython/6.2.1/bin/ipython and the ipython file /usr/local/bin/ipython has the following line in it -

PYTHONPATH="/usr/local/Cellar/ipython/6.2.1/libexec/lib/python3.6/site-packages:/usr/local/Cellar/ipython/6.2.1/libexec/vendor/lib/python3.6/site-packages" exec "/usr/local/Cellar/ipython/6.2.1/libexec/bin/ipython" "$@"

Therefore, on executing ipython in the terminal the default interpreter is taken as python3.6 by the system. How can I modify these files to change the python interpreter from 3.6 to 2.7?

Following is a screenshot of all the ipython* files in my mac.

enter image description here


Solution

  • As of version 6, IPython is no longer compatible with Python 2.x.

    You can either keep using IPython 6 with Python 3 or downgrade to IPython 5 and use Python 2.

    http://ipython.readthedocs.io/en/stable/whatsnew/version6.html#ipython-6-0 https://github.com/Homebrew/brew/issues/2849