Keep Jupyter Notebook running on GCP
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Jupyter Notebooks, a staple for data scientists, allow for interactive exploration and development of code. However, a common challenge is keeping these notebooks active, especially when deployed on platforms like Google Cloud Platform (GCP). This article provides a comprehensive guide on maintaining an active Jupyter Notebook on GCP, ensuring seamless execution and accessibility.
Setting Up Jupyter on GCP
To run Jupyter Notebook on GCP, we need to deploy it on a virtual machine (VM) using Google Compute Engine (GCE). Here are the steps:
- Create a Google Cloud Project:
- Go to the Google Cloud Console.
- Create a new project.
- Enable Billing:
- Make sure billing is activated for your project, as GCP services require this.
- Enable Compute Engine API:
- Navigate to the "APIs & Services" menu and enable the Compute Engine API.
- Launch a Google Compute Engine VM:
- Go to the "Compute Engine" section and click "Create Instance."
- Choose an appropriate machine type (e.g., n1-standard-1) and an operating system (e.g., Ubuntu).
- Configure firewall settings to allow HTTP and HTTPS traffic.
- SSH into the VM:
- Use the SSH tool in GCP Console to open a terminal to your VM.
Installing and Configuring Jupyter Notebook
On your VM instance, perform the following:
- Install Jupyter Notebook:
- Open the Jupyter configuration file located at
~/.jupyter/jupyter_notebook_config.py. - Locate the line
#c.NotebookApp.password = ''and set a password hash. - Generate a password hash using the following in a Python shell:
- Copy the generated hash into the config file.
- Edit
~/.jupyter/jupyter_notebook_config.pyto include: - Create a file named
jupyter.servicein/etc/systemd/system/. - Place the following configuration in the file:
- Use Tmux or Screen: These tools allow you to run processes in the background without being affected by session timeouts.
- Increase Idle Timeout: Configure your GCP project’s network settings to increase the TCP idle timeout settings.
- Auto SSH Key Renewal: Use Cloud Functions or cron jobs to ensure SSH keys don’t expire.
Related reading
- Keep only date part when using pandas.to_datetime
- Keras Dense layer's input is not flattened
- Keras fit model TypeError unhashable type 'numpy.ndarray
- Keras flow_from_directory read only from selected sub-directories
- Keeping EC2 Free Instances Free
- kOps 1.19 reports error Unauthorized when interfacing with AWS cluster
- Keras Image data generator throwing no files found error?
- Keras misinterprets training data shape

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.