MacOS
Install Python in MacOS systems
To follow this guide, you will need to install Homebrew first.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
After Homebrew is installed, let's install pyenv:
brew update
brew install pyenv
This command will show a list of Python versions:
pyenv install --list
Now let's install the latest Python version (3.8.5 as of this writing):
pyenv install 3.8.5
Now that Python 3 is installed through pyenv, we want to set it as our global default version for pyenv environments:
$ pyenv global 3.8.5
# and verify it worked
$ pyenv version
The power of pyenv comes from its control over our shell's path. In order for it to work correctly, we need to add the following to our configuration file (.zshrc or .bash_profile) depending on your terminal version:
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
Now create a new terminal session and run:
python -V
You should see the 3.8.5 version showing up.
Sources:
Last updated
Was this helpful?