I1 · Python Programming for AI

Setting Up a Python Environment

A Python environment is the set of tools used to write and run Python: the interpreter that runs the code, an editor or notebook to write it in, and the libraries the code uses. Common choices are a browser playground, Jupyter notebooks, VS Code and Google Colab.

10 min Intermediate Jump to the activity

What you need: The earlier topics of this module.

Definition

Where do you actually write and run Python?

A Python environment is the set of tools used to write and run Python: the interpreter that runs the code, an editor or notebook to write it in, and the libraries the code uses. Common choices are a browser playground, Jupyter notebooks, VS Code and Google Colab.

In simple words

For learning, the playground on this site is enough: it runs Python in your browser with nothing to install. Data scientists like notebooks, where code and results sit together in cells. Developers building full applications use an editor such as VS Code. Colab is a free online notebook with a GPU for heavier AI work.

Why it matters

Choosing the right tool saves time. Every later module uses notebooks for data work and an editor for building applications, so knowing both from the start makes the rest smoother.

How it works

ToolBest forInstall needed?
Browser playground (this site)Learning and quick experimentsNo
Jupyter notebookData analysis with code and charts togetherYes, or use Colab
Google ColabNotebooks with free GPUs, in the cloudNo, needs a Google account
VS CodeFull projects with many filesYes

In a notebook, code lives in cells. You run one cell at a time, and the output appears right below it. Variables stay in memory between cells.

In code

A quick check that Python works, wherever you run it.

environment_check.py
import sys

print("Python is working!")
print("Major version:", sys.version_info.major)
print("2 to the power 10 is", 2 ** 10)

Output

Python is working!
Major version: 3
2 to the power 10 is 1024

Try it yourself

Match the tool to its use

Which tool fits each situation best?

  • Trying a line of Python on a school computer with nothing installed
  • Exploring a dataset with charts next to the code
  • Training a model that needs a GPU, for free
  • Building an app with many files

Open and run a notebook

Optional, if you have a Google account.

  1. Open colab.research.google.com and create a new notebook.
  2. Type print("Hello from a notebook") in the first cell and press Shift + Enter.
  3. In a new cell, set x = 5. In the next cell, print x * 2. Notice that x is remembered.

Common mistakes

  • Spending hours installing tools before writing any code. Start in the browser.
  • Running notebook cells out of order and getting confusing results.
  • Mixing up Python 2 and Python 3 tutorials. Always use Python 3.

Check yourself

Question 1

1. Where does code live in a notebook?

Question 2

2. Which needs no installation?

Question 3

3. Which version of Python should you use?

Summary

  • An environment is the interpreter, an editor or notebook, and libraries.
  • Start in the browser; use notebooks for data and editors for apps.
  • Colab gives free cloud notebooks with GPUs.

Finished reading?

Sources: Project Jupyter