How to Create Python Development Environment In Google Cloud Platform

In this post, 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 https://console.cloud.google.com/.

Step 2

Create and connect to a virtual machine,

  1. In the Console, click Navigation menu > Compute Engine > VM Instances.

This is image title

  1. On the VM Instances page, click Create.

  2. 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.

  3. In the Identity and API access section, select Allow full access to all Cloud APIs.

  4. In the Firewall section, enable Allow HTTP traffic.

  5. Leave the remaining settings as their defaults, and click Create**.**

This is image title

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,

git clone

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.

This is image title

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 with your GCP Project ID and 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

This is image title

Summary

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

#Python #Google Cloud Platform

How to Create Python Development Environment In Google Cloud Platform
72.90 GEEK