โ† Back to TOC

Chapter 1: Environment Setup

Python 3.12+, venv, and pip

1. Install Python

Use Python 3.12 or 3.13. From python.org, enable โ€œAdd python.exe to PATHโ€ on Windows.

macOS (Homebrew)

brew install python@3.12
python3 --version

Linux

sudo apt update && sudo apt install python3.12 python3.12-venv python3-pip

๐Ÿ’ก Prefer python3 and pip3 in the shell.

2. Virtual environments

mkdir myapp && cd myapp
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip

Deactivate with deactivate.

3. Hello World

def main() -> None:
    print("Hello, Python!")

if __name__ == "__main__":
    main()
python3 hello.py

๐Ÿ”„ vs Java

if __name__ == "__main__" is the script entry point, similar in spirit to public static void main.

4. pip & requirements

pip install requests
pip freeze > requirements.txt
pip install -r requirements.txt

5. VS Code

Install the Microsoft โ€œPythonโ€ extension and select the interpreter under .venv/bin/python.

๐Ÿ“‹ Summary

Use venv per project; pin dependencies with requirements.txt or lock files in larger projects.

Loading comments...