jupyter_console icon indicating copy to clipboard operation
jupyter_console copied to clipboard

%edit does not open an editor, but silently fails.

Open gabrielmontagne opened this issue 8 years ago • 10 comments

I'm using jupyter console 5.0.0 on debian.

If I run IPython directly and %edit, it works fine, vim is opened with the buffer.

If I run %edit on jupyter console, it silently fails. If I call it without a file name or function, I can tell it's doing something, as the temp files do get created.

In [1]: %edit
IPython will make a temporary file named: /tmp/ipython_edit__pm8jcj8/ipython_edit_a_gbdwvp.py
In [2]: 

... I generated a jupyter config file, but I can't find anything that relates to external editors. I did try the IPython config c.TerminalInteractiveShell.editor = 'vim' bit it seems it made no difference.

gabrielmontagne avatar Dec 12 '16 13:12 gabrielmontagne

IPython sends the filename to edit to the frontend, but at present jupyter_console doesn't handle that information, and the Qt console is the only frontend that handles it. It shouldn't be hard to add support for it to jupyter_console, though.

takluyver avatar Dec 12 '16 14:12 takluyver

Thanks @takluyver , I used the QT console and it worked, the editor opened up and I could edit my buffer. I was super suprised, tho, that the buffer was not executed (as it would've been on a regular IPython session). Is this also expected?

gabrielmontagne avatar Dec 14 '16 09:12 gabrielmontagne

It is expected, though we know it's a confusing difference. In the terminal, we expect %edit to open a terminal editor, which only returns control to IPython when the user closes it. Things work differently in a GUI world, and many editors will return control immediately - especially if it's actually opening a new tab in a window you already have open. So we don't have a good way to tell when the user is finished editing the file, and thus we decided to separate editing and running as two separate actions.

takluyver avatar Dec 14 '16 11:12 takluyver

I have the same problem on Archlinux and jupyter console 5.1.0., behaviour is as described by gabrielmontage. The docstring of the edit magic says that after setting TerminalInteractiveShell.editor one can use %edit. This always used to work with ipython (and it still does if I run ipython or jupyter qtconsole instead of jupyter console).

simonpintarelli avatar Mar 13 '17 12:03 simonpintarelli

Should we use c.ZMQTerminalInteractiveShell.editor = 'vi' in jupyter.

This was a very helful function to edit long functions and run them in a interactive fashion..

Please bring it back.

alphaCTzo7G avatar Feb 02 '18 15:02 alphaCTzo7G

Isn't jupyter console supposed to be for terminal editing? Wonding why the restrictions/constraints in jupyter-qtconsole/notebook is preventing this feature in jupyter-console?

alphaCTzo7G avatar Feb 02 '18 15:02 alphaCTzo7G

I think the discussion has caused some confusion. The restrictions of other frontends are not preventing that feature in jupyter_console. It's not there simply because no-one has implemented it.

takluyver avatar Feb 02 '18 16:02 takluyver

Ahh I see. Is there a reason why the console part of ipython still exists? Most people use ipython through jupyter. Perhaps it would be better to combine the ipython console and jupyter console, such that if somebody just installs ipython, jupyter console is also installed by default and when ipython is started at the command prompt, its jupyter-console which is started up.

At this point, it seems jupyter-console and ipython console overlaps, and there is no need for the ipython console to exist. If we install jupyter console by default, there will be more resources to add these features into jupyter console rather than duplicating the effort across 2 libraries??

Also can you point out, how to get started? If I have some downtime, I will try to address this, as I have to connect to multiple ipython kernals through jupyter-console.

Thanks

alphaCTzo7G avatar Feb 04 '18 00:02 alphaCTzo7G

If you run ipython console, it's just a synonym for jupyter console. We kept all the old commands working when we split off Jupyter, though they'll probably go away eventually.

If you run ipython, you get a terminal interface that doesn't use the Jupyter kernel system at all. There are some things that we can do better when the interface can assume that the language is Python, and has full access to the objects the user is defining.

takluyver avatar Feb 05 '18 10:02 takluyver

I found this feature extremely useful... I'm running jupyter console on a shell to connect to a running python kernel and would like to edit there by just hitting F2, like I normally do in a plain python session.

Is there any way I can support this effort?

nachovizzo avatar Jan 08 '21 08:01 nachovizzo