Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install ipython for current python version 2.x

Tags:

python

ipython

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?

like image 473
Selah Avatar asked May 15 '15 16:05

Selah


People also ask

How do I import IPython into Python?

Create a folder called startup if it's not already there. Add a new Python file called start.py. Put your favorite imports in this file. Launch IPython or a Jupyter Notebook and your favorite libraries will be automatically loaded every time!

How do I get Python version in IPython?

To check the Python version in your Jupyter notebook, first import the python_version function with “ from platform import python_version “. Then call the function python_version() that returns a string with the version number running in your Jupyter notebook such as "3.7. 11" .


1 Answers

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.

like image 95
Padraic Cunningham Avatar answered Sep 22 '22 19:09

Padraic Cunningham