Ipython is reading the wrong version of python

I'm having problems with Python, iPython and libraries. The following points show a series of issues. I am running Python 2.7 on Mac Lion.

  • iPython does not read scipy, matplotlib libraries, but it reads numpy.
  • To fix this, I tried installing the version of the source code in Python, and it only gave me more problems, since now I have two different versions: 2.7.1 and 2.7.2
  • I noticed that working Python uses version 2.7.2 and imports scipy, matplotlib and numpy, but on iPython version 2.7.1, which does not open scipy or matplotlib.

I have tried several things that I have come across from other blogs. But none of them helped, and, unfortunately, I do not quite understand what I am doing with some of them. For example: I tried uninstalling and reinstalling ipython using easy_install and pip. I also tried reinstalling everything through homebrew and changing the .bash_profile path.

+80
python ipython
Feb 21 '12 at 22:11
source share
8 answers

Quick fix:

which python 

gives you /usr/bin/python , right? At

 which ipython 

and I'm sure there will be /usr/local/bin/ipython . Let's take a look inside:

Edit 9/7/16 - The file now looks like this:

 cat /usr/local/bin/ipython #!/usr/bin/python # -*- 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]) sys.exit(start_ipython()) 

And mine work correctly like that, but my situation is not quite like OP.




Original answer - 9/30/13:

 cat /usr/local/bin/ipython #!/usr/bin/python # EASY-INSTALL-ENTRY-SCRIPT: 'ipython==0.12.1','console_scripts','ipython' __requires__ = 'ipython==0.12.1' import sys from pkg_resources import load_entry_point if __name__ == '__main__': sys.exit( load_entry_point('ipython==0.12.1', 'console_scripts', 'ipython')() ) 

Aha - open /usr/local/bin/ipython in your editor (with privileges) and change the first line to

 #!/usr/local/bin/python 

save, run iPython, say it using the version you want now.

+125
Apr 30 '12 at 10:16
source share

How about using virtualenv? I really like it. This may not be the fastest way, but I think it is very clear.

When you create virtualenv, you can specify the python path with the -p flag.

for python 2.7

 $ virtualenv -p /usr/bin/python2.7 venv2.7 $ source venv2.7/bin/activate (venv2.7)$ pip install ipython (venv2.7)$ ipython 

for python 3.4

 $ virtualenv -p /usr/bin/python3.4 venv3.4 $ source venv3.4/bin/activate (venv3.4)$ pip install ipython (venv3.4)$ ipython 
+8
Dec 17 '15 at 10:12
source share

First off, I would make sure you use the correct python. At the command prompt, type:

 which python python -V 

The first tells you the way, the second tells you the version of Python you are using.

+6
Feb 21 '12 at 22:15
source share

A similar method using pyenv

 pyenv install 3.4.5 pyenv local 3.4.5 pip install ipython ipython 

Now it will show the correct python version

 Python 3.4.5 
+1
Sep 23 '16 at 11:40
source share

The absolute simplest solution that I could think of, which does not require intervention in the environment, installed files or something else, relies on facts that

  • The ipython is actually a Python script.
  • The IPython package is installed separately for each interpreter with which you launched pip intall with.

If the version of Python you're running with has IPython installed, you can simply do

 /path/to/desired/python $(which ipython) 

This will launch the ipython script using the interpreter you want, and not from the list specified in shebang.

+1
Jun 09 '17 at 23:29
source share

extremely important: http://conda.pydata.org/docs/troubleshooting.html#shell-command-location .

td; lr problems are encountered due to shell hashing and path variables.

0
Dec 18 '16 at 18:25
source share

Your problem is that ipython is using the correct python.

so the fix for the problem is for ipython to use the correct python (which has libraries like scipy)

I wrote a solution here:

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

0
Jun 15 '17 at 2:21
source share

I ran into the same problem, but the following was the only solution that worked for me on OSX 12, Sierra.

ipython always ran for python 3.6, but I need it for 2.7. I could not find the ipython script launch for 2.7, and could not find the IPython module to execute using python -m . None of the brew instally ipython pip install ipython or pip2 install ipython could get version 2.7. Therefore, I received it manually.

brew install ipython@5 installs version 2.7 from here , but does not put it in your $PATH because it knows that the name conflicts with another package. ln -s /usr/local/Cellar/ipython@5/5.5.0_1/bin/ipython /usr/local/bin/ipython2 fix this and let you just start ipython2 from the command line

For me, since I was serious about using ipython for 2.7, I also ran the following commands.

 ln -s /usr/local/Cellar/ipython/6.2.1/bin/ipython /usr/local/bin/ipython3 rm -f /usr/local/bin/ipython ln -s /usr/local/bin/ipython2 /usr/local/bin/ipython 
0
Oct 30 '17 at 22:28
source share



All Articles