How to run a Jupyter Notebook .ipynb file from terminal or cmd prompt ?
This tutorial guides you on how to run a Jupyter Notebook .ipynb file from terminal or cmd prompt. In our exercise I will teach you how to run a notebook file from Windows command prompt.
Run a Jupyter Notebook .ipynb file from terminal or cmd prompt
Let’s say you have installed Jupyter Notebook and created a notebook file with some code in a .ipynb file. And after some time you really don’t want the interactive feature of Jupyter Notebook and you wanted to run that code straightaway from the command prompt using Python.
Basically, you wanted to run jupyter notebook .ipynb file from terminal or cmd prompt directly. Then you are at the right place. Let’s see how to do that.
Firstly, you need to convert the jupyter notebook file which is in the format .ipynb to .py format using the jupyter nbconvert tool.
Jupyter nbconvert usage
The nbconvert tool, jupyter nbconvert converts notebook file to various other formats using jinja templates.
From the command line, you need to use the following command structure to convert Jupyter Notebook file .ipynb to a different format.
jupyter nbconvert --to <output format> <input notebook>
Whereas, the <output format> is the desired output format. And the <input notebook> is the jupyter notbook filename.
For example, to convert .ipynb file to .py (Python) file you need to run the following command.
> jupyter nbconvert --to python MyFirstNotebook.ipynb [NbConvertApp] Converting notebook MyFirstNotebook.ipynb to python [NbConvertApp] Writing 1461 bytes to MyFirstNotebook.py
Verify whether .py file is created in your working directory.
> dir Volume in drive C is Acer Volume Serial Number is BE62-23C2 Directory of C:\Users990\Documents\sneppets\Workspaces\Python\Examples 14-04-2021 15:04 <DIR> . 14-04-2021 15:04 <DIR> .. 14-04-2021 14:42 <DIR> .ipynb_checkpoints 14-04-2021 11:58 21 hello.py 14-04-2021 13:13 <DIR> img 14-04-2021 15:04 141,807 MyFirstNotebook.ipynb 14-04-2021 14:34 591 MyFirstNotebook.py 4 File(s) 142,491 bytes 4 Dir(s) 346,255,458,304 bytes free
For example, MyFirstNotebook file’s screenshot for your reference.
Finally, you could run a jupyter notebook .ipynb file from command prompt using the converted .py file as shown below.
> python MyFirstNotebook.py Hello World <IPython.core.display.HTML object> <IPython.core.display.HTML object> <IPython.core.display.HTML object>
That’s it. Hope it helped 🙂
You’ll also like:
- Run Jupyter Notebook on Windows from command line – Python ?
- How to increase the cell width of the Jupyter Notebook in browser ?
- Amazon Linux AMI : apt-get command not found
- Linux: sudo: apt-get: command not found
- How to Start Stop Restart MariaDB on Linux OS ?
- Putty Fatal Error No supported authentication methods available
- How to find which users belongs to a specific group in linux
- Give write permissions for specific user or group for specific folder in linux
- How to unzip a zip file from Terminal (Google Cloud Shell)
- Build a Docker Image with a Dockerfile and Cloud Build in GCP?
- How to create GCP project on Google Cloud Platform
- MariaDB – How to set max_connections permanently ?
- How to create GCP project on Google Cloud Platform
- Is it possible to change Google Cloud Platform Project ID ?
- Create non-root SSH user account and provide access to specific folders
- MySQL : How to grant all privileges to the user on database ?
- How to install OpenJDK 11 in Ubuntu Machine ?