Ipython: Difference between revisions

From wikinotes
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
__TOC__
An alternative/featureful python interpreter.
 
 
 
{{ TODO
| These docs are a mess, and highlight the wrong info. To be reorganized. }}
 
 
IPython is an interactive python shell, with all of the niceties that you
have come to expect from an actual shell.
 
* colours
* colours
* tab autocomplete
* tab autocomplete
Line 16: Line 6:
* readline support
* readline support


ipython is a python module that is a CROSS-LANGUAGE interpreter. Config once,
You can also install kernels for other languages, allowing you to run them within it (ex: java).
and use for python, haskell, and many others. Complete with tab completion,
syntax highlighting etc. very cool.
 


= Documentation =
= Documentation =
<blockquote>
<blockquote>
As of the move to IPython 5.0, the documentation is in the progress of being hosted on <code>Read The Docs</code>.
IPython also incorporated some other projects, and their configuration is also independent of ipython's own.
{| class="wikitable"
{| class="wikitable"
|-
|-
| http://python-prompt-toolkit.readthedocs.io/en/stable/ || || IPython5.0 readline replacement (see here for vi-style keys)
| official docs || http://ipython.readthedocs.io/en/stable/
|-
|-
| http://ipython.readthedocs.io/en/stable/               || || IPython5.0 documentation
| legacy docs || https://ipython.org/ipython-doc/3/
|-
|-
| https://ipython.org/ipython-doc/3/                     || || Legacy IPython documentation
| readline docs || http://python-prompt-toolkit.readthedocs.io/en/stable/
|-
|-
| https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages || || Other Lang Kernels (C#, Haskell, Julia,...)
| kernel docs || https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages
|-
|-
|}
|}
</blockquote><!-- Documentation -->
</blockquote><!-- Documentation -->


= Configuration =
= Locations =
<blockquote>
<blockquote>
{| class="wikitable"
{| class="wikitable"
| <code>~/.pythonrc.py</code> || || python init file
|-
|-
| <code>~/.ipython/profile_default/ipython_config.py</code> || || ipython config
| <code>~/.ipython/profile_default/ipython_config.py</code> || ipython config
|-
|-
| <code>~/.ipython/<profile>/startup/</code> || || scripts in this folder are run on startup
| <code>~/.ipython/${PROFILE}/startup/</code> || scripts in this folder are run on startup
|-
|-
|}
|}
</blockquote><!-- Locations -->


<syntaxhighlight lang="python">
= Notes =
import IPython
IPython.utils.path.get_ipython_dir() ## Find loaded profile
 
%load_ext autoreload ## Autoreload all modules before each run
%autoreload 2
</syntaxhighlight>
 
</blockquote><!-- ipython configuration -->
 
= Usage =
<blockquote>
<blockquote>
<syntaxhighlight lang="python">
{|
 
|-
cd /path/to/files ## ipython has basic shell capabilities
| [[ipython configuration]]
run script.py ## run a script (even if not on pythonpath)
|-
 
| [[ipython usage]]
 
|-
</syntaxhighlight>
|}
 
</blockquote><!-- Notes -->
== vim editing mode ==
<syntaxhighlight lang="bash">
ipython --TerminalInteractiveShell.editing_mode=vi  ## use editing-mode vi without an ipython config
</syntaxhighlight>
 
== readable colours on windows ==
If using cmder, use XTERM colourscheme. You can set ''highlighting_style'' to any pygments style.
 
<source lang="bash">
python -m IPython \
    --TerminalInteractiveShell.editing_mode=vi \
    --TerminalInteractiveShell.highlighting_style=monokai
</source>
</blockquote><!-- usage -->
 
= Logging =
<blockquote>
IPython initiates the logger before your programs are run, so all of the settings
that you normally have set using <code>logging.basicConfig()</code> are ignored.
You can modify them by using <code>logging.root</code>, which accesses the root
logger's options.
 
<syntaxhighlight lang="python">
logging.root.level = logging.DEBUG
 
</syntaxhighlight>
 
</blockquote><!-- logging -->
 
= CLI =
<blockquote>
I'm not sure why, but ipython does not create manpages. Nor do they host
their CLI documentation on the web. (I have no idea why not...).
 
In order to get help from ipython:
<syntaxhighlight lang="bash">
ipython --help-all ## generic commands
ipython help kernel ## information about specific subcommands
 
 
</syntaxhighlight>
</blockquote><!-- CLI -->


= Kernel =
= Kernel =

Latest revision as of 20:32, 19 September 2021

An alternative/featureful python interpreter.

  • colours
  • tab autocomplete
  • auto-reload all before each run
  • all of these features within a debugger
  • readline support

You can also install kernels for other languages, allowing you to run them within it (ex: java).

Documentation

official docs http://ipython.readthedocs.io/en/stable/
legacy docs https://ipython.org/ipython-doc/3/
readline docs http://python-prompt-toolkit.readthedocs.io/en/stable/
kernel docs https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages

Locations

~/.ipython/profile_default/ipython_config.py ipython config
~/.ipython/${PROFILE}/startup/ scripts in this folder are run on startup

Notes

ipython configuration
ipython usage

Kernel

There are kernels for other languages available to ipython.

ruby iruby
ijava