This tutorial shows how to prepare your local machine for Python development, including developing Python apps that run on Google Cloud.
If you already have a development environment set up, see Python and Google Cloud to get an overview of how to run Python apps on Google Cloud.
- Install the latest version of Python.
venvto isolate dependencies.
- Install an editor (optional).
- Install the Cloud SDK (optional).
- Install the Cloud Client Libraries for Python (optional).
- Install other useful tools.
Python's installation instructions vary by operating system. Follow the guide for the operating system you're running in your development environment, MacOS, Windows, or Linux.
macOS includes a version of Python by default and uses it for its own purposes. To avoid interfering with macOS, we recommend creating a separate development environment and installing the latest version of Python. To install Python, use homebrew.
To use homebrew to install Python packages, you need a compiler, which you can get by installing Xcode's command-line tools.
Install homebrew by following the instructions on the homebrew homepage, and then use homebrew to install Python as follows:
brew install python
After the installations are complete, verify that Python 3 is available as
python3, and that
pipis also installed.
To verify that Python is available, run the following command:
The output shows the version. You can learn about the latest version of Python homebrew in the Homebrew Python Formulae page.
To verify that pip is available, run the following command:
The outputs show the versions. You can learn about the latest version of pip in the pip Release Notes.
Homebrew installs the latest versions of Python available on your platform via Homebrew. The version numbers in the outputs may be different from the latest official releases of Python.
To install Python in a Windows environment, download the installers for the latest versions of Python from the Python website.
To access your version of Python, use Python launcher for Windows.
To start the latest version of Python you installed, run the following command:
To start the latest version of Python 3 you installed, run the following command:
To verify the version of pip that is available, run the following command:
py -m pip --version
The output shows the version from
You can learn about the latest version of pip in the pip Release Notes.
Most Linux distributions include recent versions of Python.
Install these packages using the following commands:
sudo apt update sudo apt install python3 python3-dev python3-venv
wget https://bootstrap.pypa.io/get-pip.py sudo python3 get-pip.py
After the installations are complete, verify that you have
The output shows the version from /usr/local/lib/python3.x/dist-packages. You can learn about the latest version of pip in the pip Release Notes.
Using venv to isolate dependencies
is a tool that creates isolated Python environments. These isolated environments
can have 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.
venvcommand to create a virtual copy of the entire Python installation. This tutorial creates a virtual copy in a folder named
env, but you can specify any name for the folder.
cd your-project python -m venv env
cd your-project py -m venv env
cd your-project python3 -m venv env
Set your shell to use the
venvpaths for Python by activating the virtual environment.
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:
You can read more about
venv in the
Installing an editor
To develop Python apps, you need an editor. Here are a few of the more popular editors (in no particular order):
Installing the Cloud Client Libraries for Python
The Cloud Client Libraries for Python is how Python developers integrate with Google Cloud services like 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
Installing the Cloud SDK
The Cloud SDK
is a set of command-line tools for Google Cloud.
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