Skip to content

Instantly share code, notes, and snippets.

@surendharreddy
Created April 25, 2021 04:12
Show Gist options
  • Save surendharreddy/3c50177d0bf724bdd927a6e8950c1cb5 to your computer and use it in GitHub Desktop.
Save surendharreddy/3c50177d0bf724bdd927a6e8950c1cb5 to your computer and use it in GitHub Desktop.
Install Python on macOS using pyenv

Install Python on Mac using pyenv

1. Install dependencies using homebrew

brew install pyenv
brew install zlib
brew install sqlite

2. Configure ~/.zshrc (our whatever shell you use)

# pyenv
export PATH="$(pyenv root)/shims:$PATH"
export PATH="$(pyenv root):$PATH"

# build python
# For compilers to find zlib and sqlite you may need to set:
export LDFLAGS="$LDFLAGS -L/usr/local/opt/zlib/lib"
export LDFLAGS="$LDFLAGS -L/usr/local/opt/sqlite/lib"
export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/zlib/include"
export CPPFLAGS="$CPPFLAGS -I/usr/local/opt/sqlite/include"

# For pkg-config to find zlib and sqlite you may need to set:
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH /usr/local/opt/zlib/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH /usr/local/opt/sqlite/lib/pkgconfig"

3. Source

source ~/.zshrc

4. Ready to use pyenv

  1. pyenv versions to get available versions
  2. pyenv install 3.8.6 to install a specific version
  3. pyenv global 3.8.6 to set python version
  4. python --version to verify the version might have to start a new terminal session
  5. pip install --upgrade pip upgrade pip to work with current python version

Thanks to

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