Setting Up Your Python Environment on Mac
Install Pyenv
First, we’re going to get a version manager. This allows you to easily install and change the python version you’re using.
brew install pyenv
When we install pyenv
, we still have to add a few lines to our shell profile for it to work in our environment. You can find up to date information on how to do this on pyenv’s github page in the installation section. The following lines should be appended to your shell profile:
# Appended to the end of my ~/.zshrc
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
After appending these lines to your shell profile, make sure to either source your profile with source ~/.zshrc
or restart your shell. Otherwise, the changes will not affect your current shell environment.
At anytime, you can enter pyenv
and it will print out a list of the available commands with helpful descriptions. So, don’t worry about memorizing or writing down any of these commands.
Install a Python Version
Now that we have pyenv
setup, we can use it to install a version of python.
pyenv install 3.10.1
Now that python version 3.10.1
is installed locally, we have to select it.
pyenv global 3.10.1
We can test that we have python setup correctly by running
python --version
This should output 3.10.1
. Congrats, you setup your python!