Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython reads wrong python version

Tags:

python

ipython

I've been having trouble with Python, iPython and the libraries. The following points show the chain of the problematics. I'm running Python 2.7 on Mac Lion.

  1. iPython doesn't read the libraries of scipy, matplotlib, but it does read numpy.
  2. To fix this, I tried installing Python's source code version, and it only gave me more problems since now I have two different versions: 2.7.1 and 2.7.2
  3. I noticed that running Python, uses version 2.7.2 and does import scipy, matplotlib, and numpy, but on iPython the version is 2.7.1 which doesn't open scipy or matplotlib.

I've tried several things that I've encountered from other blogposts. But none of them have helped, and also unfortunately I don't quite know what I'm doing with some of them. For example: I tried uninstalling and reinstalling ipython with easy_install and pip. I also tried reinstalling everything through homebrew, and modifying the path .bash_profile.

like image 314
Diego-MX Avatar asked Feb 21 '12 22:02

Diego-MX


People also ask

How do I switch between Python versions?

Yes, you should be able to switch between python versions. As a standard, it is recommended to use the python3 command or python3. 7 to select a specific version. The py.exe launcher will automatically select the most recent version of Python you've installed.

How do I change the version of Python in Jupyter Notebook?

Open a Terminal in Jupyter Notebook or Jupyter Lab and create a virtual environment. Replace the following: ${PYTHON_VERSION} with the version of Python you want to use.

Which version of Python does IPython use?

Ipython is using python 3.5 instead of 2.7.


2 Answers

Okay quick fix:

which python 

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

which ipython 

and I bet that'll be /usr/local/bin/ipython. Let's 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 works properly like this, but my situation isn't exactly like the OP's.


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, start iPython, should say it's using the version you want now.

like image 122
Manuel Ebert Avatar answered Sep 20 '22 18:09

Manuel Ebert


Posting @Matt's comment as an answer just so its more visible

python -m IPython 

Loads ipython as a module with whatever python is accessible on the path first. In my case I had one pre-installed and one I added from brew. This just works perfectly.

like image 21
sh87 Avatar answered Sep 22 '22 18:09

sh87