IPython - Command Line Options
IPython - Command Line Interface
Section titled “IPython - Command Line Interface”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.
Starting the IPython Terminal
Section titled “Starting the IPython Terminal”Simply typing ipython in your terminal launches the enhanced interactive shell:
$ ipythonPython 3.9.7 (...)Type 'copyright', 'credits' or 'license' for more informationIPython 8.0.1 -- An enhanced Interactive Python.Type '?' for help.
In [1]:Executing Scripts
Section titled “Executing Scripts”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.pyHello 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]: exitExecuting Commands
Section titled “Executing Commands”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)Common Options
Section titled “Common Options”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-automagicis recommended for clarity.--matplotlib [backend]: Enables Matplotlib integration, optionally specifying a backend (e.g.,qt5,tk). Often preferred to use%matplotlibmagic 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 Subcommands
Section titled “IPython Subcommands”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.