Skip to content

jupyter

Jupyter Notebook commands

launch_jupyter_notebook(cmd='notebook', directory=None, file=None)

Open a running jupyter server or launch one.

Parameters:

Name Type Description Default
cmd

'notebook' | 'lab'

'notebook'
directory str | None

None, or directory to start in

None
file str | None

None, or file to open

None
Source code in mmg_toolbox/tkguis/misc/jupyter.py
def launch_jupyter_notebook(cmd='notebook', directory: str | None = None, file: str | None = None):
    """
    Open a running jupyter server or launch one.

    :param cmd: 'notebook' | 'lab'
    :param directory: None, or directory to start in
    :param file: None, or file to open
    """
    running_notebooks = check_notebook_servers()
    if running_notebooks:
        webbrowser.open(running_notebooks[-1])
    else:
        popen_jupyter_server(cmd, directory, file)

popen_jupyter_server(cmd='notebook', directory=None, file=None)

Start a jupyter server quietly in the background.

Parameters:

Name Type Description Default
cmd

'notebook' | 'lab'

'notebook'
directory str | None

None, or directory to start in

None
file str | None

None, or file to open

None
Source code in mmg_toolbox/tkguis/misc/jupyter.py
def popen_jupyter_server(cmd='notebook', directory: str | None = None, file: str | None = None):
    """
    Start a jupyter server quietly in the background.

    :param cmd: 'notebook' | 'lab'
    :param directory: None, or directory to start in
    :param file: None, or file to open
    """
    command = ['jupyter', cmd]
    if directory:
        command.append('--ServerApp.root_dir=' + directory)
    elif file:
        command.append(file)
    print(f"Running: {' '.join(command)}")
    output = subprocess.Popen(command, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
    SUBPROCESSES.append(output)