Skip to main content

Installation and Runtime Choices

What You'll Learn

How to install Python correctly, create isolated environments for projects, and choose between Python versions.

Installing Python

Linux (Debian / Ubuntu)

sudo apt update
sudo apt install python3 python3-pip python3-venv -y
python3 --version

macOS

# Using Homebrew (recommended)
brew install python3
python3 --version

Windows

Download from python.org/downloads and check "Add Python to PATH" during setup.

# Verify in PowerShell
python --version

pip — The Package Manager

pip installs third-party packages from PyPI:

# Install a package
pip install requests

# Install a specific version
pip install requests==2.31.0

# List installed packages
pip list

# Uninstall a package
pip uninstall requests

# Show package info
pip show requests

Always prefer pip3 or python3 -m pip on systems with both Python 2 and 3:

python3 -m pip install requests

Virtual Environments — Why They Matter

By default, pip install puts packages in a system-wide location. This causes conflicts when:

  • Project A needs requests==2.28 but Project B needs requests==2.31
  • You're testing a new package without risking your system Python

A virtual environment is an isolated Python environment for one project:

my-project/
├── venv/ ← isolated Python + packages live here
├── app.py
└── requirements.txt

Creating and Using a Virtual Environment

# Step 1: Create
python3 -m venv venv

# Step 2: Activate
source venv/bin/activate # Linux / macOS
# venv\Scripts\activate # Windows

# Step 3: You're now inside the venv
# Your prompt changes: (venv) $

# Step 4: Install packages — they go into venv/, not system
pip install requests

# Step 5: Deactivate when done
deactivate

Check you're using the venv's Python:

which python3
# Should show: /path/to/my-project/venv/bin/python3

Saving and Restoring Dependencies

# Save what's installed to a file
pip freeze > requirements.txt

# Later: recreate the same environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

This is how you share a project — include requirements.txt in your repo, not the venv/ folder.

Python Version Choices

VersionStatusNotes
Python 3.12✅ Latest stableBest performance, all new features
Python 3.11✅ SupportedVery fast, widely used in production
Python 3.10✅ SupportedHas match statement
Python 3.9⚠️ Security onlyApproaching end-of-life
Python 2.x❌ DeadDo not use — unsupported since 2020

Use the latest 3.x unless a library forces you to an older version.

Managing Multiple Versions with pyenv

If you need multiple Python versions on the same machine:

# Install pyenv
curl https://pyenv.run | bash

# Install a Python version
pyenv install 3.12.2

# Set global default
pyenv global 3.12.2

# Set per-project version (creates .python-version file)
pyenv local 3.11.8

python3 --version

Choosing Your Editor / IDE

ToolBest For
VS CodeBeginners and pros, great Python extension
PyCharmFull IDE with built-in debugger and refactoring
vim / neovimServer-side editing, CLI-focused work
Jupyter NotebookData science, interactive exploration

For scripts and automation: any editor works. For large applications: PyCharm or VS Code.

Common Mistakes

MistakeFix
Installing packages globallyAlways use a venv
Committing venv/ to gitAdd venv/ to .gitignore
Using python instead of python3Alias or use python3 explicitly
Mixing Python 2 and 3Check python3 --version explicitly

Quick Reference

# Install Python
sudo apt install python3 python3-pip python3-venv

# Create venv
python3 -m venv venv
source venv/bin/activate

# Install packages
pip install <package>
pip freeze > requirements.txt
pip install -r requirements.txt

# Deactivate venv
deactivate

# Check version
python3 --version
pip --version

What's Next

Lesson 3: Safe Operational Mindset