7

The python version is 2.7.6 but when I install IPython

sudo pip install ipython

ipython it points to python 3.4.0. This leads to many syntax errors in modules that I commonly use due to python 3.x incompatibility.

I try editing the first line of the script /usr/local/bin/ipython:

#!/usr/bin/python3.4

becomes

#!/usr/bin/python

But then I get an error:

ImportError: No module named IPython

How can I get Ipython and my default python version (2.7.6) to work together?

0

2 Answers 2

3

Use ipython2 to start a ipython2 shell, if you need to install for python2 use pip2 install ipython. pip obviously points to python3 on your system so specifying pip2 will install ipython for python2.

Whatever the shebang points to will mean typing just ipython will start a shell for that version of python so if you had #!/usr/bin/python3.4 then ipython will start an ipython3 shell and vice-versa. Unless you have Ipython actually installed for python2 then changing the shebang won't do anything but error.

Sign up to request clarification or add additional context in comments.

2 Comments

So when I install something via pip does it always apply to only one version of python?!
@Selah, yes exactly, packages are not necessarily compatible with both versions of python, python3 is not backwards compatible with python2 so you could not install a universal package for both
1

In case you want to install Ipython for lower version of python you should check the compatibility.

If you simply try to install Ipython with the below command, there is a chance you end up installing the latest version of Ipython. Which has the compatibility issue which varies version to version.

$ pip install Ipython

Best solution would be to find the compatible version of Ipython from the below link. Ipython release history

For example Python 2.X supports Ipython below 5.X. It will be good to install

$ pip install ipython==4.2.1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.