Skip to content

Instantly share code, notes, and snippets.

@ben-ogden
Last active May 17, 2023 22:44
Show Gist options
  • Save ben-ogden/c139b8c73b81751ab3e0bbafc9282c8f to your computer and use it in GitHub Desktop.
Save ben-ogden/c139b8c73b81751ab3e0bbafc9282c8f to your computer and use it in GitHub Desktop.
macOS - Python Environment Setup

Python Environment Setup for MacOS

There are a few ways to go about this, but I prefer

  • Homebrew for package management
  • pyenv to manage Python versions, and
  • pipenv to manage Python environments.

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Make sure to follow the last steps to put brew on the path:

(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> $HOME/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

Install pyenv

brew install pyenv xz
pyenv install 3.11.3
pyenv global 3.11.3

Setup shell env for Pyenv. I use zsh:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc

Install pipenv

pip install pipenv --user

Install Xcode command line tools

xcode-select --install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment