arrow_back Python for Data & AI
Installing Python and setting up your environment

Installing Python and setting up your environment

FREE PREVIEW

Before writing a single line of code you need a working environment. This lesson gets everything installed and running.


Installing Python

Ubuntu / Debian:

sudo apt update
sudo apt install python3 python3-pip python3-venv -y
python3 --version
# Python 3.12.3

macOS (via Homebrew):

brew install python@3.12
python3 --version

Windows: Download the installer from python.org. During setup, check "Add Python to PATH" — without this, nothing will work from the terminal.


Virtual Environments — Why They Matter

Imagine installing packages globally and two projects need different versions of the same library. They will break each other. A virtual environment gives each project its own isolated box.

# Create a virtual environment called venv
python3 -m venv venv

# Activate it (Linux / macOS)
source venv/bin/activate

# Activate it (Windows)
venv\Scripts\activate

# Your prompt changes to show you are inside it:
# (venv) $

# Install packages — they go ONLY into this environment
pip install numpy pandas

# See what is installed
pip list

# Deactivate when done
deactivate

Running Python Three Ways

1. The REPL (interactive mode) — great for experimenting:

python3
>>> 2 + 2
4
>>> "hello".upper()
'HELLO'
>>> exit()

2. A script file — the normal way:

# Create hello.py with your editor, then:
python3 hello.py

3. Jupyter Notebook — best for data work:

pip install jupyter
jupyter notebook
# Opens in your browser — each cell runs independently

Or use Google Colab (colab.research.google.com) — free, no install needed, free GPU access.


Your First Script

Create a file called hello.py and add this:

print("Hello from Python!")
print("2 + 2 =", 2 + 2)
print("South Africa" * 3)

Run it:

python3 hello.py
# Hello from Python!
# 2 + 2 = 4
# South AfricaSouth AfricaSouth Africa

You are running Python. Everything else builds from here.

Duration: 16 minutes