126

It's really irritating that every time I type exit(), I get prompted with a confirmation to exit; of course I want to exit! Otherwise, I would not have written exit()!!!

Is there a way to override IPython's default behaviour to make it exit without a prompt?

Christian Stewart
  • 15,217
  • 20
  • 82
  • 139
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
  • 3
    If you want to upgrade to IPython 0.11, `exit` doesn't ask for confirmation. (Ctrl-d still does prompt, in case you hit it accidentally) – Thomas K Sep 16 '11 at 21:15

4 Answers4

143

If you also want Ctrl-D to exit without confirmation, in IPython 0.11, add c.TerminalInteractiveShell.confirm_exit = False to your config file *.

If you don't have a config file yet, run ipython profile create to create one.

Note this ticket if you're working within the Django shell.


* The config file is located at: $HOME/.ipython/profile_default/ipython_config.py

ideasman42
  • 42,413
  • 44
  • 197
  • 320
tuomassalo
  • 8,717
  • 6
  • 48
  • 50
  • The config is located at `$IPYTHONDIR/profile_default/ipython_config.py` for people who have set this environment variable – smac89 Dec 12 '20 at 20:53
47

In ipython version 0.11 or higher,

  1. Run with --no-confirm-exit OR
  2. Exit via 'exit' instead of control-D OR
  3. Make sure the directory exists (or run ipython profile create to create it) and add these lines to $HOME/.ipython/profile_default/ipython_config.py:

    c = get_config()
    
    c.TerminalInteractiveShell.confirm_exit = False
    
schlamar
  • 9,238
  • 3
  • 38
  • 76
Ernest
  • 889
  • 8
  • 11
  • `~/.config/ipython/profile_default/ipython_config.py` is preferred in Linux to match freedesktop.org. Works on 1.2.1. – Ciro Santilli OurBigBook.com Jul 08 '16 at 11:05
  • 1
    @CiroSantilli烏坎事件2016六四事件法轮功, with 3.2.1 it isn't - this version even prints `usr/lib/python3.5/site-packages/IPython/utils/path.py:291: UserWarning: Ignoring ~/.config/ipython in favour of ~/.ipython.` and in the code `We have decided to go back to using .ipython everywhere`. Apparently they changed it in some 1.x version. – maxschlepzig Jan 20 '17 at 23:21
  • re 1. `alias ipython="ipython --no-confirm-exit --no-banner"` has become my preferred way to launch ipython – jwalton Sep 03 '20 at 11:41
19

just type Exit, with capital E.

Alternatively, start IPython with:

$ ipython -noconfirm_exit

Or for newer versions of IPython:

$ ipython --no-confirm-exit 
nook
  • 2,378
  • 5
  • 34
  • 54
nye17
  • 12,857
  • 11
  • 58
  • 68
  • 22
    @Brendan, as to making it permanent, you can also set it up in your `ipythonrc` profile: `confirm_exit 0` – nye17 Sep 15 '11 at 22:34
  • 2
    Nice, set that with an alias and job done. No messing about creating profiles or changing config. – Tom Busby Mar 12 '15 at 10:58
5

I like the config suggestions, but until I learned them I've started using "Quit" key combination.

Ctrl+\

or

Ctrl+4

This just kills what is running. No time to ask questions on confirmation.

Mikhail
  • 8,692
  • 8
  • 56
  • 82
  • 11
    this is not a good practice, this make kernel send `SIGQUIT` to ipython, left no chance for ipython process to clean up itself. – georgexsh Aug 08 '16 at 06:47
  • e.g. it breaks `sudo` on my machine by changing `stty`'s output – darw Apr 16 '22 at 17:55