Getting started with Jupyter Notebooks
I started exploring and using Jupyter Notebook earlier this year for a project based on opensource enablement, licensing and operate first. This is the first time ever I was working with a notebook and apparently had to start from sratch right from understanding how it works, how it needs to be installed and finally how it is to be pushed to a repo and publish the work.
In the process of exploring the tool, I went throught quite a handful of articles and videos. Everyone’s way was a bit different than the other and there was no way correct or proper to work around this. Amongst all, I found the below way to be the most effective and clean and hence thought of penning down the learnings create a how-to guide on installing and working with Jupyter Notebooks.
This article is written based on a MacOS. Haven’t tried on a linux machine.
Jupyter Notebook = JN //for ease of writing
Prerequisites: Install python3 package
Install and launch JN
First, let’s create a virtual environment to install JN
|
|
This creates a folder called jupyter in the current dir which has a python virtual env.
To turn the venv on:
|
|
The jupyter in parenthesis lets us know that we are in our python jupyter virtual environment.
NOTE: This needs to be turned everytime you need to work with jupyter notebooks.
Now, let’s install the jupyter notebook pkg
(jupyter) parth@mac Desktop % pip3 install jupyter notebook
This installs the jupyter and notebook packages.
Creating another dir where I will be launching the JN from and where I can create pages.
|
|
Launching JN now
(jupyter) parth@mac JupyterNotebooks % jupyter notebook .
This runs a kernel process on the terminal and launches JN from the JupyterNotebooks
dir in your default web browser.
Click on the new button in the brower’s JN page to create a new page. The page can be a simple text file, a python file with .ipynb extension or markdown page with .md extention.
Any pages you create are now saved in JupyterNotebooks
dir.
Alright, we have installed and launched JN to create the pages.
Now it’s time we create a bundled book out of the pages and upload it in a git repo and publish the book.
Build and Publish the book
Follow the steps mentioned here https://jupyterbook.org/en/stable/start/overview.html
Install Jupyter Book
pip3 install -U jupyter-book
Create a sample book by running the following command:
$ jupyter-book create mynewbook/
The name mynewbook can be replaced with any other name and create option will create a skeleton of book for you.
Edit/add/modify the pages under this book.
Once you are done with creating pages and have configured _toc.yml and _config.yml, it’s time to build the book.
$ jupyter-book build mynewbook/
Use the same build option to re-build the book if you make any new changes.
The book is build. Once all the final reviews are done, it can be published in the git repository.
Follow the link below to publish the book online.
https://jupyterbook.org/en/stable/start/publish.html
Checkout some of my works based on Jupyter Notebook
Thank you for reading!