How to Install pyenv
This guide shortly describes how to install the pyenv virtual environment manager. In addition, we will install pyenv-virtualenv. This is a pyenv plugin for creating and managing virtual Python environments.
pyenv is only officially supported on Linux/MacOS systems, so we will focus on these OS environments.
Prerequisites
Homebrew
This guide assumes that you have installed the homebrew package manager.
MacOS: Xcode dependencies
If not done yet, we need to install the Xcode dependencies:
Installing pyenv
Install pyenv using homebrew:
Install extra libraries:
Install virtualenv using homebrew:
Getting Started
We can now use pyenv and pyenv-virtualenv. We start with installing a Python version.
The following command installs Python 3.11.7 in pyenv:
Since we want to keep the installed base Python version "clean2, we will create a new virtual environment, e.g. taking version 3.11.7 as a base version. The following command will create a virtual environment acme-3.11 that can be used later on:
We can now enable a virtual environment for the local directory: