Skip to content

Instantly share code, notes, and snippets.

@robinovitch61
Last active January 27, 2021 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinovitch61/76932dea346f08499086f7bee0300fb5 to your computer and use it in GitHub Desktop.
Save robinovitch61/76932dea346f08499086f7bee0300fb5 to your computer and use it in GitHub Desktop.
pyenv setup

pyenv is a python version manager. It allows you to install, activate, and set a system default for python versions like python 2.7, python 3.9, etc.

  1. Install pyenv:
curl https://pyenv.run | bash
  1. Add the following to your ~/.bashrc or ~/.zshrc
eval "$(pyenv init -)"

# for lazy loading:
pyenv() { # load pyenv on first pyenv invocation
   unset -f pyenv
   eval "$(pyenv init -)"
}
  1. Restart your shell
exec $SHELL
  1. Confirm pyenv is installed by running it
pyenv

# should see output like
pyenv 1.2.21
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   --version   Display the version of pyenv
   activate    Activate virtual environment
   commands    List all available pyenv command...
  1. Install python version desired
# list all available versions
pyenv install -l

# search for versions
pyenv install -l | grep 2.7

# install it
pyenv install 2.7.18
  1. Set your python version
pyenv global 2.7.18
  1. Confirm your python + pip versions are correct
python --version
# outputs:
Python 3.8.5 # NOTE: I previously had run `pyenv global 3.8.5`

pip --version
# outputs:
pip 20.1.1 from /Users/leo/.pyenv/versions/3.8.5/lib/python3.8/site-packages/pip (python 3.8)

which python
# outputs:
python is /Users/leo/.pyenv/shims/python
python is /usr/bin/python

which pip
# outputs:
pip is /Users/leo/.pyenv/shims/pip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment