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` 的目錄路徑

廣告