Skip to content

Instantly share code, notes, and snippets.

@mathsigit
Last active December 2, 2020 09:49
Show Gist options
  • Save mathsigit/0ee89875f1e72627a235cb742cd53ef4 to your computer and use it in GitHub Desktop.
Save mathsigit/0ee89875f1e72627a235cb742cd53ef4 to your computer and use it in GitHub Desktop.
Something about Pyenv On MacOS

Something about Pyenv On MacOS

How to install pyenv

Installing pyenv

#Via homebrew
brew update
brew install pyenv

Setting the ENV

Bash

If you using Bash, and adding the following lines to the end of ~/.bash_profile

export PATH="$HOME/.pyenv/bin:$PATH"

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

Then source the file to call the exports

source ~/.bash_profile

ZSH

If you using ZSH with oh-my-zsh, adding the pyenv plugin to the plugins array in ~/.zshrc.

plugins=(
  pyenv
)

Then source to activate the changes.

source ~/.zshrc

Using pyenv

#Check pyenv version
pyenv --version
#Check commands
pyenv --help
#List all available version of python
pyenv install -l
#Install the latest stable version
pyenv install 3.8.5
#List all version was installed
pyenv versions

* system
  2.7.18 (set by /Users/stana/.pyenv/version)
  3.7.8
  3.8.5
#Setting 3.7.8 as the default interpreter
pyenv global 3.7.8

#And verify the version we are using
python --version

The special version string system will use your default system Python. Run pyenv versions for a list of available Python versions.

Example: To enable the python2.7 and python3.7 shims to find their respective executables you could set both versions with:

pyenv global 2.7.18 3.7.8

#And verify the version we are using
python --version
#Python 2.7.18
python3 --version
#Python 3.8.5

The usage of these three commands(pyenv shell | local | global) is a bit similar, here is one of them for illustration.

# Display version
pyenv local

# Setting version
pyenv local 2.7.18 3.7.8

# Unset version
pyenv local --unset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment