Setting Up Python on macOS¶
← Back to Platform Selector | Home
Other platforms: Windows | Linux
Step 1 — Install Python¶
We recommend Python 3.13+ for the best experience. Python 3.13 has dramatically better error messages that explain what went wrong in plain English, making debugging much easier for beginners.
Option A (python.org installer):
- Download from Python releases for macOS.
- Run the installer package.
Option B (Homebrew, if installed):
Open Terminal and verify:
Expected output:
Why
python3? macOS includes an older system Python. Always usepython3to get the version you installed.
Step 2 — Install an editor¶
Option A (recommended): VS Code
Install VS Code, then add these extensions:
Option B (absolute beginners): Thonny
Thonny is a Python IDE designed for beginners. It comes with Python built in, has a simple interface, and includes a debugger that lets you step through code line by line. If VS Code feels overwhelming, start with Thonny and switch to VS Code later.
Step 3 — Create your learning folder¶
Step 4 — Install uv (recommended package manager)¶
uv is a modern, fast replacement for pip and venv. It is used throughout this curriculum.
Expected output: uv x.x.x (version number).
If you prefer pip: All
uvcommands in this curriculum have pip equivalents. Replaceuv venvwithpython3 -m venv .venvanduv pip installwithpip install. Everything else stays the same.
Step 5 — Create first project and virtual environment¶
cd "$HOME/python_sme/projects"
mkdir -p hello_sme
cd hello_sme
uv venv
source .venv/bin/activate
python --version
Expected output:
- Prompt starts with
(.venv). - Python version prints.
pip fallback: Replace
uv venvwithpython3 -m venv .venv.
Step 6 — Install pytest and run sanity checks¶
pip fallback: Replace
uv pip install pytestwithpython -m pip install pytest.
Expected output: pytest version is displayed.
Step 7 — Create first script and first test¶
Create hello.py:
Create test_hello.py:
Run:
Expected output:
Step 8 — Credential handling¶
Do not embed database credentials in scripts. Use environment variables:
Rules: keep passwords/tokens out of source code. Keep .env and secret files in .gitignore. Prefer approved enterprise secret storage when available. Use least privilege and read-only credentials first.
Expected output¶
After completing this guide you should have:
- A working
hello_smeproject withhello.py,test_hello.py, and.venv. python hello.pysucceeds.pytest -qsucceeds.- You can explain your credential safety rules.
Troubleshooting¶
python3not found: Reopen Terminal. Confirm install finished. Reinstall Python.- macOS shows old system Python: Always use
python3instead ofpython. uvnot found: Re-run the install command from Step 4. Or fall back to pip.pytestnot found: Confirm venv is active. Runuv pip install pytest(orpip install pytest).
Break/fix drills¶
- Deactivate venv and run
pytestto see failure mode. - Rename
test_hello.pytohello_test.pyand observe discovery behavior. - Intentionally misspell
assertand read the traceback. - Switch interpreter in VS Code, then switch back to the project venv.
- Add a fake credential directly in code, then remove it and replace with env var access.
Primary Sources¶
Optional Resources¶
- Thonny (beginner-friendly Python IDE)
- Automate the Boring Stuff
- Python Tutor
| ← Platform Selector | Home | Next → |
|---|---|---|