Pip / Virtual Environment Basics


  1. Install Command Line Tools for macOS and Homebrew
  2. brew install virtualenv


Because Python packaging is a pain and different dependencies conflict. Using virtual environments separates your repos so you don’t need to worry about introducing a conflict unintentionally.

Create and Use a virtual environment

cd ~/src/folder
virtualenv venv
echo venv >> .gitignore
source venv/bin/activate
pip install -r requirements.txt

venv for the folder name is an arbitrary but consistent name used.

Update all dependencies

One liner to update all

pip3 list -o | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 pip3 install -U

After confirming the updates are fine

pip freeze > requirements.txt

And compare the changes.