Getting started with Python
Beginner

Getting started with Python

In this codelab you'll install Python, learn how pip and virtual environments work, understand what Python is great for (and where other tools are a better fit), and write your first program to verify everything is set up correctly.

What you'll use

  • Python A versatile, beginner-friendly programming language used in data science, automation, AI/ML, and backend development. Learn more
  • pip Python's default package manager — installs libraries from the Python Package Index (PyPI). Learn more
  • venv A built-in tool that creates isolated Python environments so each project has its own dependencies. Learn more
20–30 min🪟 Windows & 🍎 macOS

1What is Python?

Python is one of the most popular programming languages in the world. Its readable syntax and massive ecosystem of libraries make it the go-to choice for everything from data analysis to machine learning to backend APIs.

Here's what Python is commonly used for:

  • Data science, analysis, and visualization (pandas, matplotlib, Jupyter)
  • Machine learning and AI (TensorFlow, PyTorch, scikit-learn)
  • Automation and scripting (file processing, web scraping, task scheduling)
  • Backend web development (Django, Flask, FastAPI)
  • Scientific computing and research

⚠️ Where Python isn't the best fit

Python is incredibly versatile, but there are areas where other tools are a better choice:

  • Frontend web development — JavaScript (and frameworks like React, Next.js) run in the browser; Python does not.
  • Mobile app development — Swift (iOS) and Kotlin (Android) are the standard choices.
  • High-performance systems — languages like Rust, C++, or Go are faster for CPU-intensive tasks.

🔄 Python vs. Node.js

Both Python and Node.js can build backend APIs and command-line tools. Python excels at data science and ML, while Node.js is the standard for full-stack JavaScript web development. Many developers use both. If you haven't set up Node.js yet, check out the Getting started with Node.js & npm codelab.

2Install Python

Let's install Python on your system. We recommend Python 3.10 or later.

  1. Go to python.org/downloads and click the "Download Python" button.
  2. Run the installer.

    ⚠️ Important: Check the box that says "Add python.exe to PATH" before clicking "Install Now".

  3. Open a new Command Prompt or PowerShell window when done.

Using Windows? See Pro Tip #1 to set up Git Bash as your default IDE terminal.

Verify Python installed correctly:

Terminal
python3 --version

You should see a version number like Python 3.x.x.

Verify pip is available:

Terminal
pip3 --version

pip comes bundled with Python 3.4+, so it should already be installed.

3Understanding pip

pip is Python's package manager — it installs libraries from PyPI (the Python Package Index), a public repository with over 500,000 packages.

Here are the most common pip commands:

Install a package:

Terminal
pip3 install requests

Remove a package:

Terminal
pip3 uninstall requests

See what's installed:

Terminal
pip3 list

📄 requirements.txt

Instead of installing packages one by one, Python projects use a file called requirements.txt to list all their dependencies. This is similar to how Node.js uses package.json.

A requirements.txt file looks like this:

Terminal
requests==2.31.0
flask==3.0.0
pandas==2.1.4

To install everything listed in the file:

Terminal
pip3 install -r requirements.txt

To generate a requirements.txt from your current environment:

Terminal
pip3 freeze > requirements.txt

🤖 How AI coding agents use pip When an AI agent like Google Antigravity needs a Python library, it will run pip install for you and add the package to your requirements.txt. You always have visibility into what was installed.

4Virtual environments

A virtual environment is an isolated copy of Python for a specific project. It keeps each project's dependencies separate so they don't interfere with each other — or with your system Python.

Why does this matter? Imagine two projects that need different versions of the same library. Without virtual environments, they would conflict. With virtual environments, each project gets exactly the versions it needs.

Create a virtual environment:

Terminal
python3 -m venv venv

Activate it:

Windows:

Using Windows? See Pro Tip #1 to set up Git Bash as your default IDE terminal.

Terminal
venv\Scripts\activate

macOS / Linux:

Terminal
source venv/bin/activate

You'll see (venv) appear at the beginning of your terminal prompt — this means the virtual environment is active.

To deactivate (return to normal):

Terminal
deactivate

💡 Best Practice: Always create a virtual environment for each new Python project. It's the standard workflow used by professional developers and AI coding agents alike.

AI coding agents like Google Antigravity will typically create and activate a virtual environment for you automatically when starting a Python project.

5Write & run your first program

Let's put it all together — create a project folder, set up a virtual environment, install a package, and run a simple Python program.

Create a project folder and navigate into it:

Terminal
mkdir my-python-project
cd my-python-project

Create and activate a virtual environment:

Windows:

Using Windows? See Pro Tip #1 to set up Git Bash as your default IDE terminal.

Terminal
python3 -m venv venv
venv\Scripts\activate

macOS / Linux:

Terminal
python3 -m venv venv
source venv/bin/activate

Install a package — let's use requests, a popular library for making HTTP requests:

Terminal
pip install requests

Create a file called hello.py with this code:

Terminal
import requests

response = requests.get("https://uselessfacts.jsph.pl/api/v2/facts/random")
data = response.json()

print("Here's a fun fact:")
print(data["text"])

Run your program:

Terminal
python3 hello.py

You should see a fun fact printed in your terminal — that data came from a live API on the internet, fetched using the requests library you just installed!

Save your dependencies:

Terminal
pip freeze > requirements.txt

Now anyone who clones your project can run pip install -r requirements.txt to get the exact same setup.

📖 Lesson: See how Python fits into web application architecture in our Elements of a web application lesson.

🎉

You're all set!

You now have Python installed, understand pip and virtual environments, and just ran your first Python program. You're ready to start building with Python!

Back to codelabs

How was this codelab?

Let us know what you thought — suggestions, issues, or anything else.

Getting started with Python