Jupyter Notebook Run Python Script (.py) File and Command Line: A Simple Guide

By | May 6, 2020

We can use jupyter notebook to write and run python script easily. Here is a beginner tutorial.

Getting Started with Jupyter Notebook: Installation and Run Python Script

However, in order to run python script, we have to create a new jupyter notebook. If we only want to run .py file using jupyter notebook. How to do? In this tutorial, we will introduce you how to run .py file and command line using jupyter notebook.

Run .py file

If you are using some gpu cloud platforms, they may only allow you to use jupyter notebook to run pyhon. You have uploaded some python files. To run you python application usin jupyter notebook, you can do like this:

%run your-python-script.py

For example:

%run mnist_deep.py

Which means we will use jupyter notebook to run mnist_deep.py file.

Run command line

Jupyter notebook can allow us to run some commands like terminal. The syntax is:

!command_line

For example:

!ls

ls command will be executed in jupter notebook. The result is:

run command line using jupyter notebook

Leave a Reply