Creating Python Application Development Environment In Google Cloud Platform

In this article, you will learn how to create python application development environment in google cloud platform.

Set up a Python development environment on Google Cloud Platform, using Google Compute Engine to create a virtual machine (VM) and installing software libraries for software development.
 
You perform the following tasks,
  • Provision a Google Compute Engine instance.
  • Connect to the instance using SSH.
  • Install a Python library on the instance.
  • Verify the software installation.
Prerequisites
  • Google cloud account
Follow the below steps to create a Python Application development environment in Google Cloud Platform.
 
Step 1
 
Login here.
 
Step 2
 
Create and connect to a virtual machine,
  1. In the Console, click Navigation menu > Compute Engine > VM Instances.

    How To Create Python Application Development Environment In Google Cloud Platform

  2. On the VM Instances page, click Create.
  3. On the Create an instance page, for Name type dev-instance, and select a Region as us-central1 (Iowa) and Zone as us-central1-a.
  4. In the Identity and API access section, select Allow full access to all Cloud APIs.
  5. In the Firewall section, enable Allow HTTP traffic.
  6. Leave the remaining settings as their defaults, and click Create.

    How To Create Python Application Development Environment In Google Cloud Platform
It takes about 20 seconds for the VM to be provisioned and started
 
On the VM instances page, in the dev-instance row, click SSH.
 
This launches a browser-hosted SSH session. If you have a popup blocker, you may need to click twice.
 
There's no need to configure or manage SSH keys.
 
Step 3
 
Install software on the VM instance
 
In the SSH session, to update the Debian package list, execute the following command,
 
sudo apt-get update
 
To install Git, execute the following command,
 
sudo apt-get install git
 
When prompted, enter Y to continue, accepting the use of additional disk space.
 
To install Python, execute the following command,
 
sudo apt-get install python-setuptools python-dev build-essential
 
Again, when prompted, enter Y to continue, accepting the use of additional disk space.
 
To install pip, execute the following command,
 
sudo easy_install pip
 
Step 4
 
Configure the VM to Run Application Software.
 
In this section, you verify the software installation on your VM and run some sample code.
 
Verify Python installation
 
Still in the SSH window, verify the installation by checking the Python and pip version,
 
python --version
pip --version
 
The output provides the version of Python and pip that you installed.
 
Clone the class repository,
 
 
Change the working directory,
 
cd ~/training-data-analyst/courses/developingapps/python/devenv/
 
Run a simple web server,
 
sudo python server.py
 
Step 5
 
Return to the Cloud Console VM instances list (Navigation menu > Compute Engine > Virtual Instances), and click on the External IP address for the dev-instance.
 
How To Create Python Application Development Environment In Google Cloud Platform 
 
A browser opens and displays a Hello GCP dev! message from Python.
 
Step 6
  1. Return to the SSH window, and stop the application by pressing Ctrl+c.
  2. Install the Python packages needed to enumerate Google Compute Engine VM instances,

    sudo pip install -r requirements.txt
Step 7
 
Now list your instance in Cloud Shell. Enter the following command to run a simple Python application that lists Compute Engine instances. Replace <PROJECT_ID> with your GCP Project ID and <YOUR_VM_ZONE> is the region you specified when you created your VM. Find these values on the VM instances page of the console,
 
python list-gce-instances.py <PROJECT_ID> --zone=<YOUR_VM_ZONE>
 
Your instance name should appear in the SSH terminal window.
 
Output
 
How To Create Python Application Development Environment In Google Cloud Platform 
 

Summary

 
I hope you understood how to create a Python Application development environment in Google Cloud Platform. Stay tuned for more GCP environment articles.