As part of the PyQuantNews course, we have to install Jupyter Notebook, a core application for learning.

This article will take you through the process of Starting and Stopping a Jupyter Notebook from a virtual environment, titled my_quant_lab and show various scenarios that arise from using it.

Prerequisites:

  • Ubuntu 20.04/22.04 (LTS)
  • Python version 3.9+
  • Terminal (Default Gnome-Terminal
  • Terminator (Enhanced Gnome-Terminal)
  • Brave Browser

Instructions to Start a Jupyter Notebook:

# Start Ananconda Navigator
Activities > anaconda

If you do not have an entry in the Activities menu for Anaconda, visit the article Start Anaconda Navigator Using A Menu and work through that, then return to here and continue with the next process.

# Navigate to Environments
Select 'my_quant_lab', wait until it loads
# Load Environment
Select Play Button, choose [Open Terminal] option

# Note: This action loads the default System Terminal,
# which in this case is Gnome Terminal, v3.44.0

Currently you are a default User $SHELL (/bin/bash) but not the main $SHELL
# Note: Anaconda Navigator opens an instance of
# Gnome Terminal but not in the default Userspace
dk@qbox:~$
# To confirm which $SHELL you are in, do this:
$ echo $SHELL
/bin/bash
# Source ~/.bashrc to force the $SHELL to use ~/.bashrc
$ source ~/.bashrc
dk ~ $

If you have setup the Bash ALIAS as mentioned in the Got Anaconda In Yet article, do this:

# Activate the Python Quant Environment
#
# ALIAS Method
$ conon
$ source ~/.bashrc
(base) dk ~ $

If you do not have the Bash ALIAS as mentioned in the Got Anaconda In Yet article, do this:

# Activate the Python Quant Environment
#
# Manual Method
$ conda config --set auto_activate_base True
$ source ~/.bashrc
(base) dk ~ $
# Start Jupyter Notebook; Logout flow
(base) dk ~ $ jupyter notebook
# If Successful
Browser_Tab = http://localhost:8888/tree?
# Logout of Jupyter Notebook
Select [Logout]
Browser_Tab = http://localhost:8888/logout
# Log back in from Logout Tab
Select [Proceed to the login page]

This will load a page at http://localhost:8888/login
which will request a [Password or token:]

To discover this, you will need the URL of a currently
running Jupyter Service and it's token, do this:

# Password or Token Discovery
# In another Terminal or Terminal Tab as the first one
# is still running the Jupyter Notebook session
$ jupyter notebook list
Currently running servers:
http://localhost:8888/?token=054e8ee5072c48016fc974ab42845e24d0b060f718ffa794 :: /home/dk
# Use the Discovered Token to Login
# Copy&Paste the Token from the URL string into 
# the [Password or token:] input field, Select [Log in]

# Note: Only use the Token numbers, not the string token=054...794
054e8ee5072c48016fc974ab42845e24d0b060f718ffa794

# If Successful
Browser_Tab = http://localhost:8888/tree?

# If Unsuccessful
Browser_Tab = http://localhost:8888/login?next=%2F
# Start Jupyter Notebook; Logout flow
(base) dk ~ $ jupyter notebook

# Logout of Jupyter Notebook
Select [Quit]
Browser_Tab = http://localhost:8888/tree?

You will now see a popup message stating:

Server stopped. You have shut down Jupyter. You can now close this tab.

To use Jupyter again, you will need to relaunch it.

Screenshot below:

Screenshot image of Jupyter Notebook Server Stopped message

# Exit the current Jupyter Notebook session,
# by closing the relevant tab
Close Browser_Tab = http://localhost:8888/tree?

This is a straightforward process but you need to remember where you are in the $SHELL at all times.

If in doubt, close the Terminal(s) & Browser; start again.

References: