Python App Development on Google Cloud Platform (GCP)

A Tutorial On How to Deploy Python App on GCP

Rachmawati Ari Taurisia
4 min readJul 25, 2020

Google Cloud Platform supports Python 3. If you are a python developer and you are still new in Google Cloud Platform, this article will guide you step by step. Please keep on reading

Knowing the basics Google Cloud Platform

Google Cloud Console, Cloud Shell, Google Command Line, Google Editor, Virtual Machine Instance, Google Compute Engine, Google API.

Google Cloud Console: An interface basis on the web to run the google cloud platform.

Console Google Cloud Platform

Cloud Shell: a Debian-based virtual machine and as the terminal environment for you to manage GCP projects and resources easily by typing the google command line.

Google Command Line

You can utilize this instrument to perform numerous platform tasks in scripts, or command lines, or another automation.

Reference :

https://cloud.google.com/sdk/gcloud/reference and https://cloud.google.com/sdk/docs/cheatsheet

Google Cloud Editor

https://cloud.google.com/shell/docs/viewing-and-editing-files

Virtual Machine Instance

A virtualized operating system or application environment to implement software in the cloud system that can be run on Google infrastructure.

Google Compute Engine

A Google service on the google cloud platform permits clients to dispatch virtual machines on request.

Google API

This tool is the way for you to interact on the Google Cloud Platform by enabling the APIs and Services on the google cloud console

Set Up Python Environment

Prepare the Python environment for your local machine

  • Install the latest version of Python.
  • Use venv to isolate dependencies.
  • Install an editor (optional): Sublime Text, Atom, Pycharm
  • Install the Cloud SDK (optional).
  • Install the Cloud Client Libraries for Python (optional).
  • Install other useful tools.

Step by step to Run App Dev with python on GCP

You must have an account on the GCP first. You should register for a new account if you are a new GCP user. If you already had it, log in to your GCP account.

Login to GCP Account
Welcome To GCP Account

After that, You need to create the virtual machine instance with google compute engine first.

Here are the steps to create VM instance on Google Console :

Console Google Cloud Platform
  1. On the Google Cloud Console, Choose Compute Engine, VM Instance then click create

2. Create the instance: Type The name, select the Region and the Zone

3. Allow full access to all Cloud APIs in the Identity and API section.

4. Enable Allow HTTP traffic in the firewall.

5. Create

Create VM Instance on GCP

6. Click The instance you just created on the VM instance page

7. Click SSH to open the browser window

VM Instance Page

Still in SSH Window, Now Install Software.

SSH Window

Here is a step by step guidance for you:

  1. Update The Debian Package list: Sudo apt-get update
  2. Install Git: Sudo apt-get install git
  3. Install python :

sudo apt-get install python3-setuptools python3-dev build-essential

4. Install pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Sudo python3 get-pip.py

SSH Window

Verify Python Installation

  1. python3 — version
  2. pip3 — version
  3. git clone https://github.com/GoogleCloudPlatform/training-data-analyst (This is a sample file from Google Cloud Platform)
  4. cd ~/training-data-analyst/courses/developingapps/python/devenv/
  5. sudo python3 server.py

Then Configure your Virtual Machine so you can run the Application

Navigation menu ===> Compute Engine ===> Virtual Instances, and click on the External IP address for the instance that you just created it before.

  1. Return to the SSH window, and stop the application by pressing Ctrl+c.
  2. sudo pip3 install -r requirements.txt
  3. python3 list-gce-instances.py <PROJECT_ID> — zone=<YOUR_VM_ZONE>
SSH Window

Resource & credits :

Google Cloud Platform Documentation

Qwiklabs Hands-On Google

--

--

Rachmawati Ari Taurisia
Rachmawati Ari Taurisia

Written by Rachmawati Ari Taurisia

I love to learn new things, IT learner, Self Development. Join the IT and the business community. https://www.linkedin.com/in/rachmawati-ari-taurisia-830b6786/

No responses yet