Setup on a Mac: Python, VS Code and Git

Install Homebrew, then Python, VS Code with its Python extension, Git and Git Credential Manager on a Mac, check Python with python3 --version in VS Code's terminal, see why the command is python3 on a Mac, tell Git your name and email, and make a python-course folder.

Novice · Python · Software Development · Git · Updated

By

After this lesson you can

  • Name the tools this setup installs on a Mac (Homebrew, Python, VS Code and its Python extension, Git and Git Credential Manager) and what each is for
  • Check a Mac setup in VS Code's terminal with python3 --version and git config --global --list, and explain why the command is python3

Key takeaways

  • Homebrew installs programs on a Mac when you name them with brew install, and it installs Python as python@3.15.
  • On a Mac the command is python3. Plain python isn't found until a virtual environment is turned on, which every exercise in a course does first.
  • VS Code is the code editor, its Python extension helps it understand Python, and its terminal, zsh on a Mac, is where you run your programs.
  • Git copies exercise code from GitHub and sends your work back, and Git Credential Manager signs you in to GitHub through your browser.
  • Every example and exercise goes in one folder, python-course, in your home folder.

Every Python program you'll write runs on the same few tools: Python itself, an editor to write the code in, and a terminal to run it, plus Git, to get exercise code and hand your work in. Setting them up on a Mac takes about half an hour, once. On Windows, Setup on Windows: Python, VS Code and Git is the lesson to follow instead.

What you're installing, and why

Tool What it's for Cost
Homebrew A package manager for the Mac: it installs a program when you type brew install and its name. Free
Python The interpreter that runs your programs. Homebrew's package for it is python@3.15. Free
VS Code A code editor: a text editor made for code, which colors your code and underlines some mistakes. Free
VS Code's Python extension An add-on, by Microsoft, that teaches VS Code about Python: it finishes names as you type, points out mistakes and runs your programs. Free
VS Code's terminal A window where you type a command, press Enter and read the answer. On a Mac it runs zsh (read "zee shell"). Comes with VS Code
Git and Git Credential Manager Git copies exercise code from GitHub and sends your work back. Git Credential Manager signs you in to GitHub through your browser, then remembers you. Free

Install them with Homebrew

Open the Terminal app (in Applications > Utilities, or press Cmd+Space and type terminal). Go to brew.sh, copy the install command shown at the top of the page, paste it into Terminal and press Enter. The script explains what it will do and pauses before it does it. When it asks for Password, type your Mac's password and press Enter: nothing appears as you type, which is normal.

When it finishes, read the Next steps it prints. On most Macs it lists a few commands to run so the terminal can find brew: copy and run each one. Then install the rest, one line at a time:

brew install python@3.15
brew install --cask visual-studio-code
brew install git
brew install --cask git-credential-manager

--cask (read "dash dash cask") is how Homebrew installs an app with a window, such as VS Code.

Rather not use Homebrew? python.org/downloads has a macOS installer, code.visualstudio.com has VS Code, and typing git --version in Terminal offers to install Apple's command line developer tools, which include Git.

Check it in VS Code's terminal

Open VS Code from Applications. Click the Extensions button on the left (four small squares), or press Cmd+Shift+X, search for Python, and click Install on the one by Microsoft.

Now open VS Code's own terminal: choose Terminal > New Terminal. A panel opens at the bottom of the window, with zsh waiting. Type this and press Enter:

python3 --version

--version is read "dash dash version": it asks a program which version it is. If you installed Python 3.15.2, the version this course was checked with, it answers:

Python 3.15.2

A newer number works too, and so does any Python from 3.12 on.

Why python3? Homebrew installs Python under the name python3, the name Macs and Linux computers use for Python 3, and leaves the plain name python off your terminal's list on purpose. So on a Mac, python --version answers zsh: command not found: python. Lessons write python: type python3 wherever they do. Inside a virtual environment, a private set of packages for one project that every exercise sets up first, plain python works too, and its README shows how.

Then make the folder every example and exercise goes in:

mkdir ~/python-course

~ (read "tilde") means your home folder, /Users/<you>. zsh prints nothing, which means it worked. Choose File > Open Folder, open python-course, and if VS Code asks whether you trust the authors of the files, choose Yes: they're yours.

VS Code on a Mac with the python-course folder open in the Explorer on the left, the Python extension installed, and the terminal at the bottom showing python3 --version answering Python 3.15.2

Tell Git who you are, and make a GitHub account

Git writes a name and an email on every snapshot of your work it saves. In VS Code's terminal, with your own name and email in place of the examples:

git config --global user.name "Sam Lee"
git config --global user.email "sam.lee@example.com"
git config --global init.defaultBranch main

--global means for every project on this computer, so you do it once. The third line names a new project's first branch main, the name GitHub uses. None of them prints anything. To fix a typo, run its line again. Check them:

git config --global --list
user.name=Sam Lee
user.email=sam.lee@example.com
init.defaultbranch=main

You'll also see a few credential lines that Git Credential Manager added: they're how it remembers you. Then make a free account at github.com/signup, with the same email, so GitHub links your work to you. Pick a username you'd be happy to show someone you'd like to work for: it's part of every address of your work.

If something goes wrong

What you see What to do
zsh: command not found: python Expected on a Mac: type python3 instead.
zsh: command not found: brew The terminal can't find Homebrew yet. Run the commands from Homebrew's Next steps, then open a new terminal.
python3 --version prints Python 3.9 or another number below 3.12 The terminal found Apple's older Python first. Close VS Code completely, open it again and retry; if it's still old, run Homebrew's Next steps commands again.

Check yourself

2 questions to try on the lesson page.

So what

Python, VS Code with its Python extension, and Git are the kit every Python project starts from, and the same kit professional Python developers use every day.

Key terms