Jupyter

$ jupyter

jupyter.exe                  jupyter-migrate.exe          jupyter-notebook.exe         jupyter-troubleshoot.exe
jupyter-console.exe          jupyter-nbconvert.exe        jupyter-qtconsole.exe        jupyter-trust.exe
jupyter-kernelspec.exe       jupyter-nbextension.exe      jupyter-serverextension.exe

How is the jupyter ecosystem structured?


In [33]:
!jupyter --help


usage: jupyter-script.py [-h] [--version] [--config-dir] [--data-dir]
                         [--runtime-dir] [--paths] [--json]
                         [subcommand]

Jupyter: Interactive Computing

positional arguments:
  subcommand     the subcommand to launch

optional arguments:
  -h, --help     show this help message and exit
  --version      show the jupyter command's version and exit
  --config-dir   show Jupyter config dir
  --data-dir     show Jupyter data dir
  --runtime-dir  show Jupyter runtime dir
  --paths        show all Jupyter paths. Add --json for machine-readable
                 format.
  --json         output paths as machine-readable json

Available subcommands: console kernelspec migrate nbconvert nbextension
notebook qtconsole script serverextension troubleshoot trust

In [9]:
!jupyter --paths


config:
    C:\Users\satish goda\.jupyter
    E:\Miniconda3\etc\jupyter
    C:\ProgramData\jupyter
data:
    C:\Users\satish goda\AppData\Roaming\jupyter
    E:\Miniconda3\share\jupyter
    C:\ProgramData\jupyter
runtime:
    C:\Users\satish goda\AppData\Roaming\jupyter\runtime

In [10]:
!jupyter --paths --json


{"data": ["C:\\Users\\satish goda\\AppData\\Roaming\\jupyter", "E:\\Miniconda3\\share\\jupyter", "C:\\ProgramData\\jupyter"], "runtime": ["C:\\Users\\satish goda\\AppData\\Roaming\\jupyter\\runtime"], "config": ["C:\\Users\\satish goda\\.jupyter", "E:\\Miniconda3\\etc\\jupyter", "C:\\ProgramData\\jupyter"]}

Let us pass a subcommand to jupyter. I am gonna take a wild guess here..


In [12]:
!jupyter wtf


Traceback (most recent call last):
  File "E:\Miniconda3\Scripts\jupyter-script.py", line 5, in <module>
    sys.exit(jupyter_core.command.main())
  File "E:\Miniconda3\lib\site-packages\jupyter_core\command.py", line 186, in main
    _execvp(command, sys.argv[1:])
  File "E:\Miniconda3\lib\site-packages\jupyter_core\command.py", line 104, in _execvp
    raise OSError('%r not found' % cmd, errno.ENOENT)
OSError: [Errno 'jupyter-wtf' not found] 2

Oh well! Quite expected.

So how can i find the sub commands that I can pass to the jupyter command?

YES! pyreverse to the rescue!!


In [14]:
!pyreverse --help


Usage: 
  pyreverse [options] <packages>

  create UML diagrams for classes and modules in <packages>


Options:
  -h, --help            show this help message and exit
  -f <mode>, --filter-mode=<mode>
                        filter attributes and functions according to
                        <mode>. Correct modes are :
                        'PUB_ONLY' filter all non public attributes
                        [DEFAULT], equivalent to PRIVATE+SPECIAL_A
                        'ALL' no filter                             'SPECIAL'
                        filter Python special functions
                        except constructor                             'OTHER'
                        filter protected and private
                        attributes [current: PUB_ONLY]
  -c <class>, --class=<class>
                        create a class diagram with all classes related to
                        <class>; this uses by default the options -ASmy
                        [current: none]
  -a <ancestor>, --show-ancestors=<ancestor>
                        show <ancestor> generations of ancestor classes not in
                        <projects>
  -A, --all-ancestors   show all ancestors off all classes in <projects>
  -s <ass_level>, --show-associated=<ass_level>
                        show <ass_level> levels of associated classes not in
                        <projects>
  -S, --all-associated  show recursively all associated off all associated
                        classes
  -b, --show-builtin    include builtin objects in representation of classes
  -m [yn], --module-names=[yn]
                        include module name in representation of classes
  -k, --only-classnames
                        don't show attributes and methods in the class boxes;
                        this disables -f values
  -o <format>, --output=<format>
                        create a *.<format> output file if format available.
                        [current: dot]
  --ignore=<file>       add <file> (may be a directory) to the black list. It
                        should be a base name, not a path. You may set this
                        option multiple times. [current: CVS]
  -p <project name>, --project=<project name>
                        set the project name. [current: No Name]

In [18]:
!pyreverse jupyter_core.command -p jupyter_core.command


parsing e:\miniconda3\lib\site-packages\jupyter_core\command.py...

In [20]:
!ls *.dot


classes_jupyter_core.command.dot

In [ ]:
# %load classes_jupyter_core.command.dot
digraph "classes_jupyter_core.command" {
charset="utf-8"
rankdir=BT
"0" [label="{JupyterParser|epilog\l|}", shape="record"];
}

I can now use GraphViz dot to convert to a png!


In [23]:
!dot -Tpng classes_jupyter_core.command.dot -o classes_jupyter_core.command.png

In [24]:
!ls classes_jupyter_core.command.*


classes_jupyter_core.command.dot
classes_jupyter_core.command.png

Let us now embed the image.

![](classes_jupyter_core.command.png)


In [25]:
import jupyter_core.command as jupyter_core_command

In [32]:
jupyter_core_command.JupyterParser().epilog


Out[32]:
'Available subcommands: console kernelspec migrate nbconvert nbextension notebook qtconsole script serverextension troubleshoot trust'

Ah! Now that we know all the subcommands supported by jupyter, we can start reading their help!


In [34]:
!jupyter console --help


The Jupyter terminal-based Console.

This launches a Console application inside a terminal.

The Console supports various extra features beyond the traditional single-
process Terminal IPython shell, such as connecting to an existing ipython
session, via:

    jupyter console --existing

where the previous session could have been created by another ipython console,
an ipython qtconsole, or by opening an ipython notebook.

Options

-------



Arguments that take values are actually convenience aliases to full
Configurables, whose aliases are listed on the help line. For more information
on full configurables, see '--help-all'.


--debug

    set log level to logging.DEBUG (maximize logging output)

--confirm-exit

    Set to display confirmation dialog on exit. You can always use 'exit' or
    'quit', to force a direct exit without any confirmation. This can also
    be set in the config file by setting
    `c.JupyterConsoleApp.confirm_exit`.

-y

    Answer yes to any questions instead of prompting.

--existing

    Connect to an existing kernel. If no argument specified, guess most recent

--no-confirm-exit

    Don't prompt the user when exiting. This will terminate the kernel
    if it is owned by the frontend, and leave it alive if it is external.
    This can also be set in the config file by setting
    `c.JupyterConsoleApp.confirm_exit`.

--generate-config

    generate default config file
--ssh=<Unicode> (JupyterConsoleApp.sshserver)

    Default: ''

    The SSH server to use to connect to the kernel.

--config=<Unicode> (JupyterApp.config_file)

    Default: ''

    Full path of a config file.

--existing=<CUnicode> (JupyterConsoleApp.existing)

    Default: ''

    Connect to an already running kernel

--log-level=<Enum> (Application.log_level)

    Default: 30

    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')

    Set the log level by value or name.

-f <Unicode> (JupyterConsoleApp.connection_file)

    Default: ''

    JSON file in which to store connection info [default: kernel-<pid>.json]

    This file will contain the IP, ports, and authentication key needed to

    connect clients to this kernel. By default, this file will be created in the

    security dir of the current profile, but can be specified by absolute path.

--transport=<CaselessStrEnum> (JupyterConsoleApp.transport)

    Default: 'tcp'

    Choices: ['tcp', 'ipc']

--hb=<Int> (JupyterConsoleApp.hb_port)

    Default: 0

    set the heartbeat port [default: random]

--ip=<Unicode> (JupyterConsoleApp.ip)

    Default: ''

    Set the kernel's IP address [default localhost]. If the IP address is

    something other than localhost, then Consoles on other machines will be able

    to connect to the Kernel, so be careful!

--shell=<Int> (JupyterConsoleApp.shell_port)

    Default: 0

    set the shell (ROUTER) port [default: random]

--kernel=<Unicode> (JupyterConsoleApp.kernel_name)

    Default: 'python'

    The name of the default kernel to start.

--iopub=<Int> (JupyterConsoleApp.iopub_port)

    Default: 0

    set the iopub (PUB) port [default: random]

--stdin=<Int> (JupyterConsoleApp.stdin_port)

    Default: 0

    set the stdin (ROUTER) port [default: random]

To see all available configurables, use `--help-all`

Examples
--------

    jupyter console # start the ZMQ-based console
    jupyter console --existing # connect to an existing ipython session


In [37]:
!jupyter kernelspec --help-all


Manage Jupyter kernel specifications.

Subcommands

-----------



Subcommands are launched as `jupyter kernelspec cmd [args]`. For information on
using subcommand 'cmd', do: `jupyter kernelspec cmd -h`.



list

    List installed kernel specifications.

install

    Install a kernel specification directory.

remove

    Remove one or more Jupyter kernelspecs by name.

install-self

    [DEPRECATED] Install the IPython kernel spec directory for this Python.

uninstall

    Alias for remove


Class parameters
----------------

Parameters are set from command-line arguments of the form:
`--Class.trait=value`. This line is evaluated in Python, so simple expressions
are allowed, e.g.:: `--C.a='range(3)'` For setting C.a=[0,1,2].

KernelSpecApp options
---------------------
--KernelSpecApp.log_datefmt=<Unicode>
    Default: '%Y-%m-%d %H:%M:%S'
    The date format used by logging formatters for %(asctime)s
--KernelSpecApp.log_format=<Unicode>
    Default: '[%(name)s]%(highlevel)s %(message)s'
    The Logging format template
--KernelSpecApp.log_level=<Enum>
    Default: 30
    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')
    Set the log level by value or name.


In [38]:
!jupyter kernelspec list


Available kernels:
  python3    E:\Miniconda3\lib\site-packages\ipykernel\resources

In [40]:
!jupyter script --help-all


Traceback (most recent call last):
  File "E:\Miniconda3\Scripts\jupyter-script.py", line 5, in <module>
    sys.exit(jupyter_core.command.main())
  File "E:\Miniconda3\lib\site-packages\jupyter_core\command.py", line 186, in main
    _execvp(command, sys.argv[1:])
  File "E:\Miniconda3\lib\site-packages\jupyter_core\command.py", line 104, in _execvp
    raise OSError('%r not found' % cmd, errno.ENOENT)
OSError: [Errno 'jupyter-script' not found] 2

In [41]:
!jupyter kernelspec install script


Traceback (most recent call last):
  File "E:\Miniconda3\Scripts\jupyter-kernelspec-script.py", line 7, in <module>
    main()
  File "E:\Miniconda3\Scripts\jupyter-kernelspec-script.py", line 4, in main
    KernelSpecApp.launch_instance()
  File "E:\Miniconda3\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
    app.start()
  File "E:\Miniconda3\lib\site-packages\jupyter_client\kernelspecapp.py", line 273, in start
    return self.subapp.start()
  File "E:\Miniconda3\lib\site-packages\jupyter_client\kernelspecapp.py", line 143, in start
    replace=self.replace,
  File "E:\Miniconda3\lib\site-packages\jupyter_client\kernelspec.py", line 269, in install_kernel_spec
    shutil.copytree(source_dir, destination)
  File "E:\Miniconda3\lib\shutil.py", line 303, in copytree
    names = os.listdir(src)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'script'

Jupyter Notebook


In [2]:
!jupyter notebook --help


The Jupyter HTML Notebook.

This launches a Tornado based HTML Notebook Server that serves up an
HTML5/Javascript Notebook client.

Subcommands

-----------



Subcommands are launched as `jupyter-notebook cmd [args]`. For information on
using subcommand 'cmd', do: `jupyter-notebook cmd -h`.



list

    List currently running notebook servers.


Options

-------



Arguments that take values are actually convenience aliases to full
Configurables, whose aliases are listed on the help line. For more information
on full configurables, see '--help-all'.


--generate-config

    generate default config file

--no-mathjax

    Disable MathJax
    
    MathJax is the javascript library Jupyter uses to render math/LaTeX. It is
    very large, so you may want to disable it if you have a slow internet
    connection, or for offline use of the notebook.
    
    When disabled, equations etc. will appear as their untransformed TeX source.

--script

    DEPRECATED, IGNORED

--pylab

    DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.

--no-script

    DEPRECATED, IGNORED

--debug

    set log level to logging.DEBUG (maximize logging output)

--no-browser

    Don't open the notebook in a browser after startup.

-y

    Answer yes to any questions instead of prompting.
--transport=<CaselessStrEnum> (KernelManager.transport)

    Default: 'tcp'

    Choices: ['tcp', 'ipc']

--config=<Unicode> (JupyterApp.config_file)

    Default: ''

    Full path of a config file.

--log-level=<Enum> (Application.log_level)

    Default: 30

    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')

    Set the log level by value or name.

--ip=<Unicode> (NotebookApp.ip)

    Default: 'localhost'

    The IP address the notebook server will listen on.

--port=<Int> (NotebookApp.port)

    Default: 8888

    The port the notebook server will listen on.

--notebook-dir=<Unicode> (NotebookApp.notebook_dir)

    Default: ''

    The directory to use for notebooks and kernels.

--keyfile=<Unicode> (NotebookApp.keyfile)

    Default: ''

    The full path to a private key file for usage with SSL/TLS.

--browser=<Unicode> (NotebookApp.browser)

    Default: ''

    Specify what command to use to invoke a web browser when opening the

    notebook. If not specified, the default browser will be determined by the

    `webbrowser` standard library module, which allows setting of the BROWSER

    environment variable to override it.

--pylab=<Unicode> (NotebookApp.pylab)

    Default: 'disabled'

    DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.

--certfile=<Unicode> (NotebookApp.certfile)

    Default: ''

    The full path to an SSL/TLS certificate file.

--client-ca=<Unicode> (NotebookApp.client_ca)

    Default: ''

    The full path to a certificate authority certificate for SSL/TLS client

    authentication.

--port-retries=<Int> (NotebookApp.port_retries)

    Default: 50

    The number of additional ports to try if the specified port is not

    available.

To see all available configurables, use `--help-all`

Examples
--------

    jupyter notebook                       # start the notebook
    jupyter notebook --certfile=mycert.pem # use SSL/TLS certificate

$ jupyter kernelspec

No subcommand specified. Must specify one of: ['remove', 'uninstall', 'list', 'install', 'install-self']

Manage Jupyter kernel specifications.

Subcommands
-----------

Subcommands are launched as `jupyter kernelspec cmd [args]`. For information on
using subcommand 'cmd', do: `jupyter kernelspec cmd -h`.

remove
    Remove one or more Jupyter kernelspecs by name.
uninstall
    Alias for remove
list
    List installed kernel specifications.
install
    Install a kernel specification directory.
install-self
    [DEPRECATED] Install the IPython kernel spec directory for this Python.

$ jupyter notebook list

Currently running servers:
http://localhost:8888/?token=eda3ae4c152f1294b65633eaf8dad301d6769bffa747a028 :: F:\src\GitHub

$ jupyter kernelspec list

Available kernels:
  python3    E:\Miniconda3\lib\site-packages\ipykernel\resources
$ python -m ipykernel install --user

Installed kernelspec python3 in C:\Users\satish goda\AppData\Roaming\jupyter\kernels\python3

In [4]:
!cat "C:\Users\satish goda\AppData\Roaming\jupyter\kernels\python3\kernel.json"


{
 "display_name": "Python 3",
 "language": "python",
 "argv": [
  "E:\\Miniconda3\\python.exe",
  "-m",
  "ipykernel",
  "-f",
  "{connection_file}"
 ]
}
$ /c/Python27/python.exe -m ipykernel install --user

Installed kernelspec python2 in C:\Users\satish goda\AppData\Roaming\jupyter\kernels\python2

In [5]:
!cat "C:\Users\satish goda\AppData\Roaming\jupyter\kernels\python2\kernel.json"


{
 "display_name": "Python 2", 
 "language": "python", 
 "argv": [
  "C:\\Python27\\python.exe", 
  "-m", 
  "ipykernel", 
  "-f", 
  "{connection_file}"
 ]
}

In [7]:
!E:\pyvenv\3.6\test1\Scripts\python.exe -m ipykernel install -h


usage: ipython-kernel-install [-h] [--user] [--name NAME]
                              [--display-name DISPLAY_NAME]
                              [--profile PROFILE] [--prefix PREFIX]
                              [--sys-prefix]

Install the IPython kernel spec.

optional arguments:
  -h, --help            show this help message and exit
  --user                Install for the current user instead of system-wide
  --name NAME           Specify a name for the kernelspec. This is needed to
                        have multiple IPython kernels at the same time.
  --display-name DISPLAY_NAME
                        Specify the display name for the kernelspec. This is
                        helpful when you have multiple IPython kernels.
  --profile PROFILE     Specify an IPython profile to load. This can be used
                        to create custom versions of the kernel.
  --prefix PREFIX       Specify an install prefix for the kernelspec. This is
                        needed to install into a non-default location, such as
                        a conda/virtual-env.
  --sys-prefix          Install to Python's sys.prefix. Shorthand for
                        --prefix='E:\pyvenv\3.6\test1'. For use in
                        conda/virtual-envs.

(test1) E:\pyvenv\3.6\test1\Scripts>

python.exe -m ipykernel install --name PyVenv3.6test1 --display-name "Python 3.6 venv test1" --sys-prefix

Installed kernelspec PyVenv3.6test1 in E:\pyvenv\3.6\test1\share\jupyter\kernels\pyvenv3.6test1

In [5]:
!ls E:\pyvenv\3.6\test1\share\jupyter\ -R


E:\pyvenv\3.6\test1\share\jupyter\:
kernels
nbextensions

E:\pyvenv\3.6\test1\share\jupyter/kernels:
pyvenv3.6test1

E:\pyvenv\3.6\test1\share\jupyter/kernels/pyvenv3.6test1:
kernel.json
logo-32x32.png
logo-64x64.png

E:\pyvenv\3.6\test1\share\jupyter/nbextensions:
jupyter-js-widgets

E:\pyvenv\3.6\test1\share\jupyter/nbextensions/jupyter-js-widgets:
extension.js
extension.js.map

(test1) E:\pyvenv\3.6\test1\Scripts> jupyter.exe --paths

config:
    C:\Users\satish goda\.jupyter
    e:\pyvenv\3.6\test1\etc\jupyter
    C:\ProgramData\jupyter
data:
    C:\Users\satish goda\AppData\Roaming\jupyter
    e:\pyvenv\3.6\test1\share\jupyter
    C:\ProgramData\jupyter
runtime:
    C:\Users\satish goda\AppData\Roaming\jupyter\runtime