## Install Homebrew on Mac `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` ## Install pyenv to Manage Your Python Versions `brew install pyenv` ## Use pyenv to Install Python or Update Your Python Version `pyenv install 3.9.2` ## Set Up Your MacOS PATH for pyenv (Bash or ZSH) #### For Bash ``` echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.bash_profile source ~/.bash_profile ``` OR add the Open your ~/.bash_profile then add the commands below at the bottom ``` export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)" ``` #### For ZSH ``` echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)"\nfi' >> ~/.zshrc source ~/.zshrc ``` ## Troubleshooting: Some guides will use `eval "$(pyenv init -)"` instead of `eval "$(pyenv init --path)"` In my case `eval "$(pyenv init --path)"` worked System: - MacOS Majove v10.14.6 - Homebrew 3.2.5 - pyenv 2.0.4 ## How to remove Pyenv from mac https://github.com/pyenv/pyenv#uninstalling-pyenv The simplicity of pyenv makes it easy to temporarily disable it, or uninstall from the system. 1. To **disable** Pyenv managing your Python versions, simply remove the `pyenv init` invocations from your shell startup configuration. This will remove Pyenv shims directory from `PATH`, and future invocations like `python` will execute the system Python version, as it was before Pyenv. `pyenv` will still be accessible on the command line, but your Python apps won't be affected by version switching. 2. To completely **uninstall** Pyenv, remove _all_ Pyenv configuration lines from your shell startup configuration, and then remove its root directory. This will **delete all Python versions** that were installed under the `` $(pyenv root)/versions/ `` directory: ```sh rm -rf $(pyenv root) ``` If you've installed Pyenv using a package manager, as a final step, perform the Pyenv package removal. For instance, for Homebrew: ``` brew uninstall pyenv ``` ## Sources: https://www.freecodecamp.org/news/python-version-on-mac-update/ https://github.com/pyenv/pyenv/issues/849