First, make sure python is installed on your mac.
% python --version
zsh: command not found: python
% pyenv -v
zsh: command not found: pyenv
copy command from https://brew.sh/index
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
% brew -v
Homebrew 3.6.17
% brew install pyenv
% pyenv -v
pyenv 2.3.12
% echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
% echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
% echo 'eval "$(pyenv init -)"' >> ~/.zshrc
% source ~/.zshrc
% pyenv install --list
.
.
3.11.0
3.11-dev
3.11.1
3.12.0a4
3.12-dev
activepython-2.7.14
.
.
Select 3.11.1.
% pyenv install 3.11.1
% pyenv versions
* system
3.11.1
% pyenv global 3.11.1
% python --version
Python 3.11.1
% vim test.py
make test file
test.py
print('Hello, world!')
Run a test file.
% python test.py
Hello, world!
Confirmation of current status
% python --version
Python 3.11.1
% pyenv versions
system
* 3.11.1
install version
% pyenv install 3.10
% pyenv versions
system
3.10.9
* 3.11.1
change version
% pyenv global 3.10.9
% python --version
Python 3.10.9