title: What is pyenv?
tags:
- python
- pyenv
permalink: what-is-pyenv
date created: Friday, October 20th 2023, 9:44:08 pm
date modified: Friday, April 25th 2025, 11:35:25 am
For example, it allows you to create one project with Python 3.13, and another with 3.12.
Install pyenv with Homebrew.
brew install pyenv
If you have trouble installing, consider installing these pre-requisites.
xcode-select --install
brew update && brew install openssl readline sqlite3 xz zlib tcl-tk
List Python choices.
pyenv install -l
Filter the list. For example, list all available Python 3.13.x versions:
pyenv install -l | grep 3.13
Install a Python version, like python_version="3.13.2"
.
pyenv install ${python_version}
Install other versions. You can now switch between them.
You can also unset the local Python version.
pyenv local --unset
If pyenv local is not working, or .python-version is not respected, run this:
pyenv shell --unset
Switch back to the system Python.
pyenv global system
If an existing Python version installation gives you trouble, uninstall and reinstall. If that doesn't work, uninstall the version, install the pre-requisites below.
brew install openssl readline zlib xz
You may need to add these to your .zshrc
file.
export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib"
export CPPFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix readline)/include -I$(brew --prefix zlib)/include"
export PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix readline)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig"