IPython - 命令行选项



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

调用 IPython 程序

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

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

文件选项是一个带有 .py 扩展名的 Python 脚本。如果没有给出其他选项,则执行脚本并重新出现命令提示符。

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

子命令和参数

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

  • 配置文件 - 创建和管理 IPython 配置文件。

  • 内核 - 启动一个没有附加前端的内核。

  • 定位 - 打印 IPython 目录的路径。

  • 历史记录 - 管理 IPython 历史记录数据库。

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

  • ipython profile create myprofile - 创建一个新的配置文件。

  • ipython profile list - 列出所有可用的配置文件。

  • ipython locate profile myprofile - 定位所需的配置文件。

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

Ipython kernel –install –name

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

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

此外,我们知道:

  • history 子命令管理 IPython 历史记录数据库。

  • trim 选项将 IPython 历史记录数据库缩减到最后 1000 个条目。

  • clear 选项删除所有条目。

IPython 的一些其他重要命令行选项列在下面:

序号 IPython 命令和描述
1

--automagic

打开自动调用魔法命令。

2

--pdb

在每次异常后启用自动调用 pdb 调试器。

3

--pylab

预加载 matplotlib 和 numpy 以与默认的 matplotlib 后端进行交互式使用。

4

--matplotlib

配置 matplotlib 以与默认的 matplotlib 后端进行交互式使用。

5

--gui=options

启用 GUI 事件循环与 ('glut', 'gtk', 'gtk2','gtk3', 'osx', 'pyglet', 'qt', 'qt4', 'qt5', 'tk', 'wx', 'gtk2', 'qt4') 中的任何一个集成。

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

序号 IPython 命令和描述
1

ipython --matplotlib

启用 matplotlib 集成

2

ipython --matplotlib=qt

启用使用 qt4 后端的 matplotlib 集成

3

ipython --profile=myprofile

使用配置文件 foo 启动

4

ipython profile create myprofile

使用默认配置文件创建配置文件 foo

5

ipython help profile

显示配置文件子命令的帮助

6

ipython locate

打印 IPython 目录的路径

7

ipython locate profile myprofile

打印配置文件 `myprofile` 的目录路径

广告