IPython workflow (edit, run)

Viewed 33972

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?

14 Answers

Personally, I like PyScripter. Unfortunately, it only works on Windows, but also runs perfectly in Wine.

If you like the work-flow under Matlab, then you probably should try the following two:

1, Try the combination of Spyder and Vim.

  • Edit python files in Vim (Spyder can reload the file automatically)

  • Run the code in Spyder (in the same interpreter, which is important for me):

  • Use F9 to run the current file

  • Ctrl+F9 to run the selected block

2, Use Vim + conque-shell. (on google code)

  • Open your preferred Python interpreter in Vim,

    e.g., just :ConqueTermSplit python.

  • then visual select some Python code

  • press F9 to paste and run it in the Python interpreter buffer.

Note: a few more:

  • :ConqueTermVSplit python,

  • :ConqueTerm python

  • :ConqueTermVSplit rlwrap python

    If your interpretor misses readline, you can use rlwrap.

sudo apt-get install ipython

Once you are done with installing ipython.

Start ipython from terminal (just hit ipython in the ternminal)

To run ravi.py file all you need to do is

%run ravi.py

The latest version of IdleX supports IPython within IDLE, as well as the %edit magic. You can run your files from the IDLE editor within the IPython shell many ways, either by F5 (run everything), F9 (run a selection), or Ctrl+Enter (run a subcode).

I want to suggest excellent plugin for vim that makes two-way integration between Vim and IPython: vim-ipython.

From project page on http://github.com/ivanov/vim-ipython:

Using this plugin, you can send lines or whole files for IPython to execute, and also get back object introspection and word completions in Vim, like what you get with: object? and object. in IPython.

This plugin has one big limitation: it doesn't support python 3 (it's planned).

Try Ptpython. It has much better integration with VIM. You can directly edit in VIM by just pressing V. It also allows browsing your history.. so you can pretty much code in the shell, and incrementally build up your code.

If you are already familiar with ipython, you can check the advantages of ptpython here:

https://www.youtube.com/watch?v=XDgIDslyAFM

I just use the exclamation mark (!) to run vi as a shell command

In [1]: !vi myScript.py

and when done with editing I just quit vi to get back to the Ipython shell.

To run the script one can then use

In [2]: %run myScript.py

as suggested in another answer and not !python ... because the Python version in ipython might be different from the one in the underlying shell.

If you want to dump some code in a file use the magic %%writefile

 In [3]:%%writefile myScript.py
    ...: print("hello")
    ...: 
    ...: 

Be careful because this will overwrite myScript.py. To append use %%writefile -a.

Related