As per this great video (on maintaining local python environments using pyenv), the Python that comes built into the Mac is for the Mac to use, not for programmers to use!
Moreover, sudo should be unnecessary when working with installing modules, etc. for python. This magic is achievable by doing the following:
- Install Homebrew (this is the only step that requires sudo)
- Use brew to install pyenv
- Use pyenv to install the version(s) of python you want
- Install pip to install any necessary python modules.
Install Homebrew
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
The install will prompt a couple of PATH modifications you need to make
Install pyenv and python and make necessary PATH modifications for your shell.
brew install pyenv
pyenv install 3.12.0
pyenv global 3.12.0
install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
That should be good to go. You can type ‘pyenv versions’ to sanity check your work.