Skip to content

IPython - Command Line Options

While many users interact with IPython primarily through Jupyter Notebook or JupyterLab, the ipython command itself provides a powerful terminal-based interactive shell with various command-line options.

Simply typing ipython in your terminal launches the enhanced interactive shell:

$ ipython
Python 3.9.7 (...)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.1 -- An enhanced Interactive Python.
Type '?' for help.
In [1]:

You can run a Python script directly using IPython. After the script finishes, IPython exits.

# Assuming hello.py contains: print('Hello from script!')
$ ipython hello.py
Hello from script!

To run a script and then enter an interactive session (useful for inspecting the script’s state), use the -i flag:

# Assuming script.py contains: x = 100
$ ipython -i script.py
In [1]: print(x)
# Output: 100
In [2]: exit

Use the -c flag to execute a specific Python command and then exit:

$ ipython -c "import sys; print(sys.version)"
# Output: (Prints Python version info)

Some other useful command-line options include:

  • --no-banner: Suppresses the IPython startup banner.
  • --no-confirm-exit: Skips the confirmation prompt when exiting.
  • --automagic / --no-automagic: Enables/disables calling magic commands without the leading ’%’. Default is usually ON, but --no-automagic is recommended for clarity.
  • --matplotlib [backend]: Enables Matplotlib integration, optionally specifying a backend (e.g., qt5, tk). Often preferred to use %matplotlib magic within the session.
  • --log-level: Sets the logging level (e.g., DEBUG, INFO, WARN, ERROR).
  • --profile=<name>: Starts IPython using a specific configuration profile.

IPython also provides subcommands for managing its configuration and components:

  • ipython profile create [name]: Creates a new configuration profile.
  • ipython profile list: Lists available profiles.
  • ipython locate [profile <name>]: Shows the location of the IPython directory or a specific profile directory.
  • ipython kernel: Starts a kernel process (less common for direct use, usually managed by frontends like Jupyter).
  • ipython history trim / clear: Manages the command history database.
$ ipython profile create my_custom_settings
# Output: [ProfileCreate] Generating default config file: .../.ipython/profile_my_custom_settings/ipython_config.py
$ ipython locate profile my_custom_settings
# Output: (Path to the profile directory)

For a full list of options and subcommands, run ipython --help.