views:

418

answers:

4

Is there a GUI for IPython that allows me to open/run/edit Python files? My way of working in IDLE is to have two windows open: the shell and a .py file. I edit the .py file, run it, and interact with the results in the shell.

Is it possible to use IPython like this? Or is there an alternative way of working?

+3  A: 

When I'm working with python, I usually have two terminal windows open - one with IPython, and the other with a fairly customized Vim.

Two good resources:


Though it sounds like what you want is IPython's magic function %ed/%edit:

An example of what you can do:

In [72]: %ed
IPython will make a temporary file named: c:\docume~1\wjwe312\locals~1\temp\ipython_edit_ar8veu.py

In the file I put:

x = "Hello World"
print 3

After saving and quitting the file:

Editing... done. Executing edited code...
3
Out[72]: "x = 'Hello world'\nprint 3\n"

In [73]: x
Out[73]: 'Hello world'

You can define functions or anything else - just remember that the contents of the file will be executed when you close it.

Another similar workflow is to cd to the directory containing your Python script that you're editing with your favorite editor. Then you can %run the script from within IPython and you'll have access to everything defined in the file. For instance, if you have the following in the file test.py in your /home/myself directory:

    class Tester(object):
        def __init__(self):
            print "hi"

    def knightme(name):
        print "Hello, Sir ", name

Then you can do the following:

In [42]: cd /home/myself
/home/myself

In [43]: %run test.py # <Tab> autocomplete also works

In [44]: knightme('John')
Hello, Sir  John

In [45]: t = Tester()
Hi

Either a mix or one of those workflows should give you something very similar to the way you're used to working in IDLE.

Wayne Werner
If you just want to edit a file from ipython without executing it, do `%edit -x <file>`.
ma3
ma3204, that is incredibly useful! I'm probably barely competent with IPython - I just use it like an advanced "regular" shell. It's got a lot of features I just don't know about.
Wayne Werner
A: 

Personally, I use what @Wayne suggested, a combination of vim and ipython...

However, if you'd prefer a different approach, take a look at spyder.

As of the latest version (1.1) ipython should be fully integrated. If you download an earlier version, things will work fine with ipython as an external shell, but you won't get a few of spyder's nifty features (like viewing all of the currently defined variables in the workspace window).

Spyder is definitely a bit heavyweight, but it's an interesting project.

Another (very, very, new) similar project to take a look at is iep. It will (sort-of) work with ipython as shell, and I'd be willing to be bet that nicer ipython integration will be along before too long. At any rate, iep is essentially a more lightweight alternative to spyder.

Both of these are oriented towards scientific computing, and so have nice integration with things like matplotlib (and thus can automatically run gui main loops in a seperate thread). They're not quite like "normal" IDE's but they may fill the niche you're looking for quite nicely.

Joe Kington
+1  A: 

SPyderlib a.k.a Spyder2

Pretty lightweight, fast and support almost all features you will ever need to work with a python project.

svvn
A: 

Take a look at DreamPie. Might be what you are looking for.

Amin Abbaspour