Setting up a Python development environment
This tutorial shows how to prepare your local machine for Python development,
including developing Python apps that run on Google Cloud Platform (GCP).
Objectives
- Install the latest versions of Python 2 and 3.
- Install and use virtualenv.
- Install an editor (optional).
- Install the Cloud SDK (optional).
- Install the Cloud Client Libraries for Python (optional).
- Install other useful tools.
Installing and using the virtualenv tool
virtualenv is a tool that creates isolated Python environments. These isolated
environments can have their own separate versions of Python packages, which allows
you to isolate one project's dependencies from the dependencies of other projects. We
recommend that you always use a per-project virtual environment when developing
locally with Python.
1- Install virtualenv globally.
To install pip with Python 2 or Python 3, use pip install --upgrade virtualenv.
2- After you install virtualenv, you can create a virtual environment in your project.
virtualenv creates a virtual copy of the entire Python installation in the env folder.
Use the --python flag to tell virtualenv which Python version to use:
cd your-project
virtualenv --python python3 env
You might need to specify the full path to the Python installation directory:
virtualenv --python "c:\python36\python.exe" env
3- After the copy is created, set your shell to use the virtualenv paths for Python by
activating the virtual environment as follows.
.\env\Scripts\activate
4- Now you can install packages without affecting other projects or your global Python
installation:
pip install google-cloud-storage
If you want to stop using the virtual environment and go back to your global Python, you
can deactivate it:
deactivate
Installing an editor
To develop Python apps, you need an editor. Here are a few of the more popular
editors :
- Sublime Text by Jon Skinner
- Atom by GitHub
- PyCharm by JetBrains
Installing the Cloud SDK
The Cloud SDK is a set of tools for Google Cloud Platform (GCP). It contains gcloud, gsutil,
and bq, which you can use to access Compute Engine, Cloud Storage, BigQuery, and
other products and services from the command line. You can run these tools
interactively or in your automated scripts.
Installing the Cloud Client Libraries for Python
The Cloud Client Libraries for Python is how Python developers integrate with GCP
services like Cloud Datastore and Cloud Storage. To install the package for an individual
API like Cloud Storage, use a command similar to the following:
pip install --upgrade google-cloud-storage