Home

Python on Mac

Using the latest deep learning technology means using more Python.

As a frequent user of Node.JS, I find when I dive back into Python, I need a refresher on how it all works on Mac. Here's my quick getting started guide.

The Python environmental protection agency wants to seal it in a cement chamber, with pictorial messages to future civilizations warning them about the danger of using sudo to install random Python packages.
My brain everytime I need to use Python

Install w/ Homebrew

$ brew install python@3.11

Update alias

This allows you to use the python command to run Python 3.

# ~/.zshrc
alias python=python3

Setup environment

Environment management keeps your project dependencies isolated from each other.

# Move to a project folder
$ cd ~/projects/my-project

# Create an environment
$ python -m venv env

# Activate the environment
$ source env/bin/activate

Confirm that the python command is now pointing to the correct environment.

$ type -a python
# python is an alias for python3
# python is /Users/username/projects/my-project/env/bin/python

Install packages and save to requirements.txt

$ pip install some-package && pip freeze > requirements.txt

Install from requirements

$ pip install -r requirements.txt
© Mike Surowiec