差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
python:ipython [2019/07/24 21:55] – 作成 ともやん | python:ipython [2024/03/09 05:27] (現在) – [IPython] ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
- | ====== ipython のインストール | + | ====== |
+ | <WRAP #logo> | ||
+ | {{python: | ||
+ | </ | ||
+ | \\ | ||
+ | 本家: [[https://ipython.org/ | ||
+ | ソースコード: | ||
+ | ドキュメント: | ||
+ | \\ | ||
+ | **IPython** (アイパイソン) は Python を対話的に実行するためのシェルである。CPython 内蔵の対話的に実行するためのシェルと比べ、型イントロスペクション (英語: Type introspection) 機能、対話的実行のための文法などが追加されてあり、コードのシンタックスハイライトおよびタブによる補完が行える。IPython の開発は NumFOCUS によって財政的に支援されている。\\ | ||
+ | [[wwjp> | ||
+ | |||
+ | ===== インストール ===== | ||
- | ===== Linux ===== | + | ==== Linux ==== |
< | < | ||
$ pip3 install ipython | $ pip3 install ipython | ||
</ | </ | ||
- | ===== Windows | + | ==== Windows ==== |
< | < | ||
- | > pip3 install ipython | + | > pip install ipython |
</ | </ | ||
- | <WRAP prewrap 100%> | + | <WRAP prewrap 100% # |
< | < | ||
Collecting ipython | Collecting ipython | ||
行 66: | 行 78: | ||
</ | </ | ||
+ | ===== IPython の動作確認 ===== | ||
+ | |||
+ | ==== Linux ==== | ||
+ | < | ||
+ | $ ipython | ||
+ | </ | ||
+ | |||
+ | ==== Windows ==== | ||
+ | < | ||
+ | > ipython | ||
+ | </ | ||
+ | <WRAP prewrap 100% # | ||
+ | < | ||
+ | Python 3.7.4 (tags/ | ||
+ | Type ' | ||
+ | IPython 7.6.1 -- An enhanced Interactive Python. Type '?' | ||
+ | |||
+ | In [1]: ? | ||
+ | |||
+ | IPython -- An enhanced Interactive Python | ||
+ | ========================================= | ||
+ | |||
+ | IPython offers a fully compatible replacement for the standard Python | ||
+ | interpreter, | ||
+ | history mechanism and output results caching. | ||
+ | |||
+ | At your system command line, type ' | ||
+ | options available. This document only describes interactive features. | ||
+ | |||
+ | GETTING HELP | ||
+ | ------------ | ||
+ | |||
+ | Within IPython you have various way to access help: | ||
+ | |||
+ | ? -> Introduction and overview of IPython' | ||
+ | object? | ||
+ | object?? | ||
+ | %quickref -> Quick reference of all IPython specific syntax and magics. | ||
+ | help -> Access Python' | ||
+ | |||
+ | If you are in terminal IPython you can quit this screen by pressing `q`. | ||
+ | |||
+ | |||
+ | MAIN FEATURES | ||
+ | ------------- | ||
+ | |||
+ | * Access to the standard Python help with object docstrings and the Python | ||
+ | manuals. Simply type ' | ||
+ | |||
+ | * Magic commands: type %magic for information on the magic subsystem. | ||
+ | |||
+ | * System command aliases, via the %alias command or the configuration file(s). | ||
+ | |||
+ | * Dynamic object information: | ||
+ | |||
+ | Typing ?word or word? prints detailed information about an object. Certain | ||
+ | long strings (code, etc.) get snipped in the center for brevity. | ||
+ | |||
+ | Typing ??word or word?? gives access to the full information without | ||
+ | snipping long strings. Strings that are longer than the screen are printed | ||
+ | through the less pager. | ||
+ | |||
+ | The ?/?? system gives access to the full source code for any object (if | ||
+ | available), shows function prototypes and other useful information. | ||
+ | |||
+ | If you just want to see an object' | ||
+ | quotes, and without % if you have automagic on). | ||
+ | |||
+ | * Tab completion in the local namespace: | ||
+ | |||
+ | At any time, hitting tab will complete any available python commands or | ||
+ | variable names, and show you a list of the possible completions if there' | ||
+ | no unambiguous one. It will also complete filenames in the current directory. | ||
+ | |||
+ | * Search previous command history in multiple ways: | ||
+ | |||
+ | - Start typing, and then use arrow keys up/down or (Ctrl-p/ | ||
+ | through the history items that match what you've typed so far. | ||
+ | |||
+ | - Hit Ctrl-r: opens a search prompt. Begin typing and the system searches | ||
+ | your history for lines that match what you've typed so far, completing as | ||
+ | much as it can. | ||
+ | |||
+ | - %hist: search history by index. | ||
+ | |||
+ | * Persistent command history across sessions. | ||
+ | |||
+ | * Logging of input with the ability to save and restore a working session. | ||
+ | |||
+ | * System shell with !. Typing !ls will run ' | ||
+ | |||
+ | * The reload command does a ' | ||
+ | module since you imported will actually be available without having to exit. | ||
+ | |||
+ | * Verbose and colored exception traceback printouts. See the magic xmode and | ||
+ | xcolor functions for details (just type %magic). | ||
+ | |||
+ | * Input caching system: | ||
+ | |||
+ | IPython offers numbered prompts (In/Out) with input and output caching. All | ||
+ | input is saved and can be retrieved as variables (besides the usual arrow | ||
+ | key recall). | ||
+ | |||
+ | The following GLOBAL variables always exist (so don't overwrite them!): | ||
+ | _i: stores previous input. | ||
+ | _ii: next previous. | ||
+ | _iii: next-next previous. | ||
+ | _ih : a list of all input _ih[n] is the input from line n. | ||
+ | |||
+ | Additionally, | ||
+ | being the prompt counter), such that _i<n> == _ih[< | ||
+ | |||
+ | For example, what you typed at prompt 14 is available as _i14 and _ih[14]. | ||
+ | |||
+ | You can create macros which contain multiple input lines from this history, | ||
+ | for later re-execution, | ||
+ | |||
+ | The history function %hist allows you to see any part of your input history | ||
+ | by printing a range of the _i variables. Note that inputs which contain | ||
+ | magic functions (%) appear in the history with a prepended comment. This is | ||
+ | because they aren't really valid Python code, so you can't exec them. | ||
+ | |||
+ | * Output caching system: | ||
+ | |||
+ | For output that is returned from actions, a system similar to the input | ||
+ | cache exists but using _ instead of _i. Only actions that produce a result | ||
+ | (NOT assignments, | ||
+ | Mathematica, | ||
+ | variables. | ||
+ | |||
+ | The following GLOBAL variables always exist (so don't overwrite them!): | ||
+ | _ (one underscore): | ||
+ | __ (two underscores): | ||
+ | ___ (three underscores): | ||
+ | |||
+ | Global variables named _<n> are dynamically created (<n> being the prompt | ||
+ | counter), such that the result of output <n> is always available as _<n>. | ||
+ | |||
+ | Finally, a global dictionary named _oh exists with entries for all lines | ||
+ | which generated output. | ||
+ | |||
+ | * Directory history: | ||
+ | |||
+ | Your history of visited directories is kept in the global list _dh, and the | ||
+ | magic %cd command can be used to go to any entry in that list. | ||
+ | |||
+ | * Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython) | ||
+ | |||
+ | 1. Auto-parentheses | ||
+ | |||
+ | | ||
+ | this (notice the commas between the arguments):: | ||
+ | |||
+ | In [1]: callable_ob arg1, arg2, arg3 | ||
+ | |||
+ | and the input will be translated to this:: | ||
+ | |||
+ | | ||
+ | |||
+ | This feature is off by default (in rare cases it can produce | ||
+ | | ||
+ | by starting IPython with `--autocall 1`, set it permanently in your | ||
+ | | ||
+ | |||
+ | You can force auto-parentheses by using '/' | ||
+ | of a line. For example:: | ||
+ | |||
+ | In [1]: / | ||
+ | |||
+ | Note that the '/' | ||
+ | | ||
+ | |||
+ | In [2]: print / | ||
+ | |||
+ | In most cases the automatic algorithm should work, so you should | ||
+ | | ||
+ | are trying to call a function with a list of tuples as arguments (the | ||
+ | | ||
+ | |||
+ | In [1]: zip (1, | ||
+ | |||
+ | but this will work:: | ||
+ | |||
+ | In [2]: /zip (1, | ||
+ | ------> zip ((1, | ||
+ | Out[2]= [(1, 4), (2, 5), (3, 6)] | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | In [18]: callable list | ||
+ | -------> callable (list) | ||
+ | |||
+ | 2. Auto-Quoting | ||
+ | |||
+ | You can force auto-quoting of a function' | ||
+ | the first character of a line. For example:: | ||
+ | |||
+ | In [1]: , | ||
+ | |||
+ | If you use ';' | ||
+ | | ||
+ | |||
+ | In [2]: , | ||
+ | In [3]: ; | ||
+ | |||
+ | Note that the ',' | ||
+ | | ||
+ | |||
+ | In [4]: x = , | ||
+ | |||
+ | In [2]: | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ====== ☢️古い資料です (Obsolete)☢️ ====== | ||
+ | |||
+ | ===== IPythonの導入 ===== | ||
+ | -pip を利用する場合、以下のコマンドを実行する。< | ||
+ | > pip install ipython pyreadline</ | ||
+ | Downloading/ | ||
+ | Downloading ipython-0.12.1.tar.gz (4.3Mb): 4.3Mb downloaded | ||
+ | Running setup.py egg_info for package ipython | ||
+ | |||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | warning: no files found matching ' | ||
+ | warning: no previously-included files found matching ' | ||
+ | warning: no previously-included files found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | Downloading/ | ||
+ | Downloading pyreadline-2.0-dev1.zip (109Kb): 109Kb downloaded | ||
+ | Running setup.py egg_info for package pyreadline | ||
+ | |||
+ | package init file ' | ||
+ | Installing collected packages: ipython, pyreadline | ||
+ | Running setup.py install for ipython | ||
+ | |||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | warning: no files found matching ' | ||
+ | warning: no previously-included files found matching ' | ||
+ | warning: no previously-included files found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | no previously-included directories found matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | warning: no previously-included files matching ' | ||
+ | Installing ipcontroller-script.py script to C: | ||
+ | Installing ipcontroller.exe script to C: | ||
+ | Installing ipcontroller.exe.manifest script to C: | ||
+ | Installing iptest-script.py script to C: | ||
+ | Installing iptest.exe script to C: | ||
+ | Installing iptest.exe.manifest script to C: | ||
+ | Installing ipcluster-script.py script to C: | ||
+ | Installing ipcluster.exe script to C: | ||
+ | Installing ipcluster.exe.manifest script to C: | ||
+ | Installing ipython-script.py script to C: | ||
+ | Installing ipython.exe script to C: | ||
+ | Installing ipython.exe.manifest script to C: | ||
+ | Installing pycolor-script.py script to C: | ||
+ | Installing pycolor.exe script to C: | ||
+ | Installing pycolor.exe.manifest script to C: | ||
+ | Installing iplogger-script.py script to C: | ||
+ | Installing iplogger.exe script to C: | ||
+ | Installing iplogger.exe.manifest script to C: | ||
+ | Installing irunner-script.py script to C: | ||
+ | Installing irunner.exe script to C: | ||
+ | Installing irunner.exe.manifest script to C: | ||
+ | Installing ipengine-script.py script to C: | ||
+ | Installing ipengine.exe script to C: | ||
+ | Installing ipengine.exe.manifest script to C: | ||
+ | Installing ipython-qtconsole-script.pyw script to C: | ||
+ | Installing ipython-qtconsole.exe script to C: | ||
+ | Installing ipython-qtconsole.exe.manifest script to C: | ||
+ | Running setup.py install for pyreadline | ||
+ | package init file ' | ||
+ | |||
+ | Successfully installed ipython pyreadline | ||
+ | Cleaning up... | ||
+ | </ | ||
+ | - Windows の場合は C: | ||
+ | |||
+ | ==== IPythonの導入(Windows編) ===== | ||
+ | - [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | - ipython-x.xx.x.win32-setup.exe を実行してインストールを行う。 | ||
+ | - pyreadline-x.x-win32-setup.exe を実行してインストールを行う。 | ||
+ | - コマンドラインより動作確認を行う。< | ||
+ | > ipython | ||
+ | C: | ||
+ | from sets import Set | ||
+ | Python 2.6.2 (r262: | ||
+ | Type " | ||
+ | |||
+ | IPython 0.9.1 -- An enhanced Interactive Python. | ||
+ | ? -> Introduction and overview of IPython' | ||
+ | %quickref -> Quick reference. | ||
+ | help -> Python' | ||
+ | object? | ||
+ | |||
+ | In [1]: | ||
+ | </ | ||
+ | * 「DeprecationWarning: | ||
+ | * ここで ipython を実行しても以下のようなエラーになる場合< | ||
+ | > ipython | ||
+ | ' | ||
+ | 操作可能なプログラムまたはバッチ ファイルとして認識されていません。 | ||
+ | </ | ||
+ | C: |