Jupyter 简明教程

IPython - Command Line Options

在本章中,让我们了解如何使用 IPython 中的各种命令行选项。

In this chapter, let us understand how to work with various command line options in IPython.

Invoking IPython Program

你可以使用以下选项调用 IPython 程序:

You can invoke an IPython program using the following options −

C:\python36> ipython [subcommand] [options] [-c cmd | -m mod | file] [--] [arg]

file 选项是一个 Python 脚本,扩展名为 .py。如果没有给出其他选项,将执行该脚本并重新显示命令提示符。

The file option is a Python script with .py extension. If no other option is given, the script is executed and command prompt reappears.

C:\python36>ipython hello.py
Hello IPython
welcome to interactive computing

Subcommands and Parameters

IPython 命令接受以下子命令选项:

An IPython command accepts the following subcommand options −

  1. Profile − Create and manage IPython profiles.

  2. Kernel − Start a kernel without an attached frontend.

  3. Locate − Print the path to the IPython dir.

  4. History − Manage the IPython history database.

IPython 配置文件子命令接受以下参数:

An IPython profile subcommand accepts the following parameters −

  1. ipython profile create myprofile − Creates a new profile.

  2. ipython profile list − Lists all available profiles.

  3. ipython locate profile myprofile − Locates required profile.

要安装新的 IPython 内核,请使用以下命令 −

To install new IPython kernel, use the following command −

Ipython kernel –install –name

要打印出 IPython 目录的路径,请使用以下命令 −

To print the path to the IPython dir, use the following command −

C:\python36>ipython locate myprofile
C:\Users\acer\.ipython

此外,我们还知道 −

Besides, we know that −

  1. The history subcommand manages IPython history database.

  2. The trim option reduces the IPython history database to the last 1000 entries.

  3. The clear option deletes all entries.

以下列出了 IPython 的其他一些重要的命令行选项 −

Some of the other important command line options of IPython are listed below −

Sr.No.

IPython Command & Description

1

--automagic Turn on the auto calling of magic commands.

2

--pdb Enable auto calling the pdb debugger after every exception.

3

--pylab Pre-load matplotlib and numpy for interactive use with the default matplotlib backend.

4

--matplotlib Configure matplotlib for interactive use with the default matplotlib backend.

5

--gui=options Enable GUI event loop integration with any of ('glut', 'gtk', 'gtk2','gtk3', 'osx', 'pyglet', 'qt', 'qt4', 'qt5', 'tk', 'wx', 'gtk2', 'qt4').

某些 IPython 命令行选项的示例用法显示在以下表格中 −

The sample usage of some of the IPython command line options are shown in following table −

Sr.No.

IPython Command & Description

1

ipython --matplotlib enable matplotlib integration

2

ipython --matplotlib=qt enable matplotlib integration with qt4 backend

3

ipython --profile=myprofile start with profile foo

4

ipython profile create myprofile create profile foo w/ default config files

5

ipython help profile show the help for the profile subcmd

6

ipython locate print the path to the IPython directory

7

ipython locate profile myprofile print the path to the directory for profile myprofile