Tuesday, August 02, 2011

IPython & PyDev

In the current nightly build (see: http://pydev.org/download.html to get it), IPython can be used as the backend for the PyDev interactive console.

IPython is a Python shell that provides many improvements over the standard Python shell (more details may be found at http://ipython.org/ ).

To use it, install IPython (0.10.x or 0.11) in your Python interpreter (if you use easy-install, just do easy_install ipython), make sure that the IPython paths are properly added in your interpreter configuration inside of PyDev ( http://pydev.org/manual_101_interpreter.html ) and start up the interactive console in PyDev ( http://pydev.org/manual_adv_interactive_console.html ). If all is properly configured, the interactive shell should use IPython as the backend (if it's not found, it'll fallback to the standard PyDev shell and warn that IPython could not be found).

Another improvement in the shell is that the output for a long running command will now be printed while it's executing, and not only after it returns.

I'm waiting for feedback to know if there's something missing in the integration before a final release is provided with the integration...


Christoph said...

I am trying to use ipython in PyDeV without success so far. What do you mean by "make sure that the IPython paths are properly added in your interpreter configuration inside of PyDev".

Here's my setup:
- Mac OS X 10.7 with python 2.7 and ipython 0.11 installed via MacPorts
- Eclipse Indigo with PyDev version

When I start a python console I don't get an ipython shell, although import IPython works:

import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python 2.7.2 (default, Jul 23 2011, 13:25:29)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)]
import IPython
Out[3]: '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/__init__.pyc'

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages is added to the "system libs" in the pydev config.
What else is needed for pydev to find ipython?

Fabio Zadrozny said...

Actually, it seems you have an IPython-based shell (it's just that IPython 0.11 no longer prints a welcome as it did on 0.10, but it's being used as your backend -- is there some IPython command you're trying that's not working as it should?)

p.s.: The fact that it's printing "Out[3]:" makes me 100% sure that you're really using the IPython backend.

zvikico said...

Mac users who encounter issues with line scrolling when using IPython should reinstall readlines using easy_install and not PIP. See this answer.

Another interesting alternative to the standard python shell is bpython.

Jason said...

I get an error.

System running OSX 10.6.8
Python Enthought EPD 7.1 (python2.7, iPython 0.11)

Error getting info on interpreter.
Common reasons include
- Using an unsupported version
- Specifying an invalid interpreter.

The details:
See error log for details.
Unable to recreate the Interpreter info (Its format changed. Please, re-create your Interpreter information).Contents found:ipython [options] [files]

...there was a bunch more about iPython that was too long to post.

I'd really like to highlight some code and execute it in the iPython console.

Fabio Zadrozny said...

I think you're trying to configure ipython.exe. What you should do is configure python.exe (as regular following the steps at: http://pydev.org/manual_101_interpreter.html ), and start the shell and it'll automatically pick IPython (PyDev imports IPython and uses it -- the ipython executable is not used)

Anonymous said...

On linux it's not working with indigo and helios. I still have the standard pydev console but no warning at all. Do I have to remove or modify something in the "interactive console" configuration? (Actually the initial interpreter command is: mport sys; print('%s %s' % (sys.executable or sys.platform, sys.version))

Message when I open a console:

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
/usr/bin/python2.7 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2]

So it's not ipython.

pydev version:

Fabio Zadrozny said...

Actually, if you have no warning saying that it's NOT IPython, then it is IPython (in 0.11 they're not printing the standard welcome message).

Anonymous said...

My normal shell can detect ipython. But django shell cannot

Fabio Zadrozny said...

How are you starting the shell? (for me, when starting the shell for Django it always gets it with IPython configured).

Joseph Coffey said...

I think that you are trapping the stack traces somehow when ipython dies on an exception.

Usually after:
ValueError: value does not have the same key

you can type %debug and get into the the stack but in pydev:

>>> %debug
ERROR: No traceback has been produced, nothing to debug.

Fabio Zadrozny said...

Please report that as a bug in the pydev sf tracker. See: http://pydev.org/about.html

Anonymous said...


Some more feedback. I have been trying to start ipython as well but with no luck so far.

Actually I cannot get the python interpreter to be configured properly, as when I add the absolute path to the ipython executable, this one seems to be replaced with some message, and what appears in the Location field of the Python Interpreter is a long string like

/User/homedir/.ipythonInitializing from configuration: /some/path/Ipython/UserConfigSuccessful Upgrade!All files in your directory /Users/homedir/.ipythonwhich would have been overwritten by the upgrade bla bla bla...

My config:
Mac Os X 10.7, python 2.6 and ipython 0.10.1 via macports
eclipse indigo
PyDev for Eclipse

The normal python and Jython console start without a problem.


Fabio Zadrozny said...

Please create a bug report with the full error.

Anonymous said...

Thanks for great iPython integration with PyDev - works a treat. The only other thing I would really like is to use iPython also in the debug console. I find it quite frustrating in particular that there is no command history with 'up arrow', as well as other iPython features.

Michael P said...

I'm also having no luck with PyDev and IPython. I have installed Eclipse and PyDev and everything works.

I'm using Python(x,y) which is a Python distribution for scientists.

Python(x,y) installed IPython in C:\Python27\Scripts.

Under PyDev preferences, I went to the Python Interpreter preferences and add C:\Python27\Scripts to the PYTHONPATH and clicked Apply. PyDev did some processing.

But when I go to create a new PyDev console I get following message:

PyDev console: using default backend (IPython not available).

Any ideas what could be going wrong?

I'm using Eclipse Helios Service Release 2 and PyDev 2.2.3.



Unknown said...

I also am having problems getting IPython to work in PyDev:

>>> import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
/usr/bin/python2.6 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5]
PyDev console: using default backend (IPython not available).
>>> import IPython
>>> IPython.__file__

If anyone can help with more specifics on what configuration is necessary for PyDev to use IPython I'd be very grateful...!

Fabio Zadrozny said...


Please create a bug report specifying the IPython version you're using.

Also, please add the result of executing:

from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell


from IPython.frontend.prefilterfrontend import PrefilterFrontEnd

to the bug report

Fabio Zadrozny said...

@Michael P

Please follow the same instructions I passed for @Unknown...

Unknown said...

hi fabio

I have the same problem as michael p.

with pydev 2.3 I add my ipytyhon path c:/python26/scripts (the default) but it is not picked up.

I have ipython 0.11

the output to the two commands you requestsed are

from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named terminal.interactiveshell
from IPython.frontend.prefilterfrontend import PrefilterFrontEnd
Traceback (most recent call last):
File "", line 1, in
File "C:\Python26\lib\site-packages\ipython-0.10.1-py2.6.egg\IPython\frontend\prefilterfrontend.py", line 32, in
from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap
File "C:\Python26\lib\site-packages\ipython-0.10.1-py2.6.egg\IPython\kernel\__init__.py", line 25, in
from IPython.kernel.error import TaskRejectError
File "C:\Python26\lib\site-packages\ipython-0.10.1-py2.6.egg\IPython\kernel\error.py", line 20, in
from twisted.python import failure
ImportError: No module named twisted.python

I would ifle a bug but I'm not sure where.



Fabio Zadrozny said...

You said you had ipython 0.11, yet, your traceback maps to ipython 0.10 (maybe that's part of your problem?)

If you're not able to find it out, please ask about it in stackoverflow with a pydev tag giving details on your configuration, etc. (this blog isn't the proper place for these questions).

If you think it's a bug (and not a misconfiguration on your side), please report it at the pydev bugs tracker (in sourceforge).

Anonymous said...

I am having trouble adding the ipython interpreter in the pydev interpreter preference window. I get the following error:

Error getting info on interpreter.
Common reasons include:
-using an unsupported version
-specifying an invalid interpreter.

The path to the interpreter I am trying to specify is /Library/Frameworks/Python.framework/Versions/Current/bin/ipython.

Is this not the proper interpreter file? What is the proper interpreter file?

I am running on Mac OS 10.7.2, and pydev 2.3

Fabio Zadrozny said...


Please ask at stackoverflow with a 'pydev' tag (this blog is not the proper place for support questions).

Anonymous said...


great post, thanks for the explanation.

Everything works fine, except I am not able to use tab-completion in my IPython through Pydev in Eclipse (Debian 6 64bit VM guest on a 64bit Windows 7 Pro host).

Any Ideas why this might be?

Fabio Zadrozny said...

@Anonymous: can you ask related on tab-complete on StackOverflow (with a PyDev tag)?

Anonymous said...

Apparently Ipython 0.12 associated. I solved this problem by commenting out all lines containing @testdec.skip_doctest in file C:\Python27\Lib\site-packages\IPython\Magic.py


T said...

I'm on Aptana Studio 3, with PyDev 2.7.0. I've got the pythonxy distribution, and when I do a pip freeze | grep ipython, I am told that my ipython version is 0.13.1.

However, when I pull up the PyDev console, I get this:

C:\Python27\python.exe 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]
PyDev console: using IPython 0.11

IPython versions do not match! Is this expected or something wrong with my setup?

also, is there any chance of integrating the ipython QTconsole with PyDev? Is it even possible? I like the fact that plot are not blocking.

Fabio Zadrozny said...

Hi T,

Probably your PYTHONPATH is not correct (you can double-check it printint sys.path).

It's possible to make the console non-blocking in PyDev (I made some experiments in the past for that), but it's not high in my priority list right now...



Sven Prevrhal said...

I never got it to work, it always defaulted to the standard shell. Now I installed Python(x,y) "C:\Python27\python.exe 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel), iPython 0.11]" and it works! (Eclipse Indigo, PyDev for Eclipse Don't know why though :-)

What doesn't work and looks like a bug is the prompt is still >>> instead of the "In[x]" prompt, and Out is always Out[1], i.e. the run number never increments.

luigi said...

To get Ipython as standard shell do the followings: go to Window-->Preferences-->PyDev-->Interactive Console. In the Initial Interpreter Commands filed add this 2 commands: import IPython; IPython.Shell.IPShell().mainloop() Now every time you'll start your console IPython will be launched as default.

Note1: of course,you need IPython installed of your system for this to work
Note2: the interpreter will still complain with something like "In [1]: PyDev console: using default backend (IPython not available)" but it is because it prints it automatically before you have the chance to import IPython.

Hope this helps!! Bye!!

Andrew said...

I have ipython installed and the pydev console is running with it as the backend of the interactive console. Is there any way I can choose NOT to use ipython? It is preventing sys.last_traceback from being set such that pdb.pm and ipdb.pm both fail to return me to the last uncaught error.


Fabio Zadrozny said...

Hi Andrew,

There's no such option in the UI, but you can manually edit plugins\org.python.pydev\pysrc\pydevconsole.py and change the line:

from pydev_ipython_console import InterpreterInterface

to a "pass" to achieve that.