Setting up a Python development environment

This tutorial shows how to prepare your local machine forPython development, including developing Python apps that run on Google Cloud.

If you already have a development environment set up, seePython and Google Cloud to get an overview of how to run Python apps on Google Cloud.

Tip: If you want to get started quickly,Cloud Shell Editor provides IDE supportfor the full development cycle of Google Kubernetes Engine and Cloud Runapplications. Cloud Shell Editor is based onCode OSSand comes with the Google Cloud CLI and Cloud Code toolspreinstalled.

Objectives

  • Install asupported version of Pythoncompatible with Google Cloud.
  • Usevenv to isolate dependencies.
  • Install an editor (optional).
  • Install the Google Cloud CLI (optional).
  • Install the Cloud Client Libraries for Python (optional).
  • Install other useful tools.
  • Set up authentication (optional).

Installing Python

Python's installation instructions vary by operating system. Follow theguide for the operating system you're running in your development environment,macOS, Windows, or Linux.

macOS

macOS includes a version of Python by default and uses it for its ownpurposes. To avoid interfering with macOS, we recommend creating a separatedevelopment environment and installing asupported version of Pythonfor Google Cloud. To install Python, usehomebrew.

  1. To use homebrew to install Python packages, you need acompiler, which you can get by installingXcode's command-line tools.

    xcode-select--install
  2. Install homebrew by following the instructions on thehomebrew homepage,and then use homebrew to install Python as follows:

    brewinstallpyenvpyenvinstallPYTHON_VERSION

    Python version number should be in the format ofx.y. For example:

    pyenvinstall3.12
  3. After the installations are complete, verify that Python 3 is availableaspython andpython3, and thatpip is also installed.

    To verify that Python is available, run the following command:

    python3--version

    The output shows the version. You can learn about Python homebrew on theHomebrew Python Formulaepage, and then check your version.

    To verify thatpip3 is available, run the following command:

    pip3--version

    If installed, the output shows thepip3 version. For more about thelatest version ofpip3, see thepip Release Notes.

    If the preceding command does not show thepip3 version, make sure thatpip3 is installed correctly. Ifpip3 is installed but not working,upgrade to the latest version using the following command:

    python-mpipinstall--upgradepip

    Homebrew installs the latest versions of Python available on yourplatform. The version numbers in the outputs might bedifferent fromthe latest official releases of Python.

Windows

  1. To install Python in a Windows environment, download theinstaller for the version of Python you need from thePython website.For more information, see thesupported versions of Pythonfor Google Cloud.

  2. To access your version of Python, usePython launcher for Windows.

    To start the version of Python you installed, run the following command:

    py

    To start the version of Python 3 you installed, run the followingcommand:

    py-3

    To verify the version ofpip that is available, run the following command:

    py-mpip--version

    The output shows the version fromC:\users\[USERNAME]\appdata\local\programs\python\python38-32\lib\site-packages.

    You can learn about the latest version ofpip in thepip Release Notes.

Linux

Most Linux distributions include recent versions of Python.

  1. To install Python in a Linux environment, install theappropriate packages for your distribution. For Debian and Ubuntu, thesepackages arepython3,python3-dev,python3-venv, andpython3-pip,

    Install these packages using the following commands:

    sudoaptupdatesudoaptinstallpython3python3-devpython3-venvpython3-pip
  2. After the installations are complete, verify that you havepip installed:

    pip3--version

    You can learn about the latest version ofpip in thepip Release Notes.

Using venv to isolate dependencies

venv is a tool that creates isolated Python environments. These isolated environmentscan have separate versions of Python packages, which lets youisolate one project's dependencies from the dependencies of other projects. Werecommend that you always use a per-project virtual environment when developinglocally with Python.

  1. Use thevenv command to create a virtual copy of the entire Pythoninstallation. This tutorial creates a virtual copy in a folder namedenv,but you can specify any name for the folder.

    macOS

    cdyour-projectpython-mvenvenv

    Windows

    cdyour-projectpy-mvenvenv

    Linux

    cdyour-projectpython3-mvenvenv
  2. Set your shell to use thevenv paths for Python by activating the virtualenvironment:

    macOS

    sourceenv/bin/activate

    Windows

    .\env\Scripts\activate

    Linux

    sourceenv/bin/activate
  3. Now you can install packages without affecting other projects or your globalPython installation:

    pipinstallgoogle-cloud-storage

    If you want to stop using the virtual environment and go back to your globalPython, you can deactivate it:

    deactivate

You can read more aboutvenv in thevenv docs.

Note: If you're usingAnaconda, follow the instructions on their website.

Installing an editor

To develop Python apps, you need an editor. Here are a few of the more populareditors (in no particular order):

Installing the Cloud Client Libraries for Python

The Cloud Client Libraries for Pythonis how Python developers integrate with Google Cloud serviceslike Datastore and Cloud Storage. To install the package for anindividual API like Cloud Storage, use a command similar to the following:

pipinstall--upgradegoogle-cloud-storage

Installing the gcloud CLI

Thegcloud CLI is a set of command-line tools for Google Cloud. It containsgcloud andbq, which you can use to access Compute Engine, Cloud Storage,BigQuery, and other products and services from the command line. Youcan run these tools interactively or in your automated scripts.

Set up authentication

To use the client library, you must first set up authentication.

If you're using a local shell, then create local authentication credentials for your user account:

gcloudauthapplication-defaultlogin

You don't need to do this if you're using Cloud Shell.

If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

For more information, seeAuthenticate for using client libraries.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.