Are you looking for an interactive GUI for Python development? Jack Wallen shows you how to deploy a Jupyter Notebook for that very purpose.
A Jupyter Notebook serves as an interactive computing environment for developers to author notebook documents which contain live Python 3 code, interactive widgets, plots, narrative text, equations, images, video, and much more. Think of this as a digital scrapbook for your development project, one that also allows you to run your Python 3 code from within a web browser.
I want to show you how to deploy a Jupyter Notebook, so you can take your Python 3 development to the next level.
What you’ll need
I’ll be demonstrating this process on Ubuntu Desktop 20.04, but you can do this on any platform that supports Python 3. You will obviously need to adjust the steps for installing Python on your platform of choice–if it isn’t already installed. You’ll also need a user with sudo privileges.
How to install Python 3
The first thing we’ll do is install Python 3. More than likely, it’s already there on your system. If not, you can add it with a single command:
sudo apt-get install python3 -y
Next, we need to install a piece of software that will allow you to create virtual environments for Python with the command:
sudo apt-get install python3-venv -y
Finally, we must install PIP (the tool used to install Python packages) with the command:
sudo apt-get install python3-pip -y
How to install Voila and Jupyter
We now move on to the installation of Voila (a piece of software that allows you to view Jupyter Notebooks via a web browser) and Jupyter itself. First we’ll install Voila.
Create a new directory with the command:
mkdir ~/voila
Change into that new directory with the command:
cd ~/voila
Create a new virtual environment with the command:
python -m venv venv
Load the necessary pre-defined variables with the source command like so:
source venv/bin/activate
Install Voila with the command:
pip install voila
Once the Voila installation completes, you can now install Jupyter. We’ll install a couple of Python libraries (NumPy and Matplotlib) along with this, using the command:
pip install jupyter numpy matplotlib
SEE: Top 5 programming languages for systems admins to learn (free PDF) (TechRepublic)
How to deploy the Jupyter Notebook
With all of the dependencies out of the way, it’s time to deploy the Jupyter Notebook. To do this, issue the command:
jupyter notebook
After the command successfully runs, it will present you with two URLs, in the form of:
http://localhost:8888/?token=TOKEN
Where TOKEN is a long string of random characters.
Click on one of those URLs to open the Jupyter Notebook (Figure A).
Figure A
In the resulting page, click the New drop-down, select Python 3, and you’ll be greeted by a new page with an empty cell ready for you to add your Python code (Figure B).
Figure B
Type your code in the cell and run it by clicking the Run button. You should see the output of the code below the cell (Figure C).
Figure C
And that’s all there is to deploying a Jupyter Notebook. This incredibly handy tool can help make your Python programming so much more efficient. Give it a try and see if you don’t wind up favoring this environment over a terminal window for your Python programming.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.
Also see
Source of Article