How to create and open a jupyter notebook ipynb file directly from terminal

Open notebook in browser

jupyter notebook <notebook>.ipynb

Create empty, minimal notebook:

"""create-notebook.py
   Creates a minimal jupyter notebook (.ipynb)
   Usage: create-notebook <notebook>
"""
import sys
from notebook import transutils as _
from notebook.services.contents.filemanager import FileContentsManager as FCM

try:
    notebook_fname = sys.argv[1].strip('.ipynb')
except IndexError:
    print("Usage: create-notebook <notebook>")
    exit()

notebook_fname += '.ipynb'  # ensure .ipynb suffix is added
FCM().new(path=notebook_fname)

Alias create-notebook script:

alias create-notebook='python $(pwd)/create-notebook.py'

Putting it all together

create-notebook my_notebook && jupyter notebook my_notebook.ipynb

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)