pyenv lets you install, manage, and switch between multiple versions of Python itself. For example, you can have Python 3.8, 3.9, and 3.10 all installed on the same machine without them interfering with each other.
- Primary Goal: To select which version of Python your computer or a specific project folder should use (e.g.,
python --versioncould return3.9.7in one folder and3.10.4in another). - What it Manages: The Python interpreters installed on your system.
- Use Case: You need to work on an old project that requires Python 3.7, but your new project needs Python 3.11.
pyenvmakes switching between them easy.
We can set the Python version:
- Globally: For your entire user account.
- Per-shell: For your current terminal session.
- Per-Project (most common): By placing a
.python-versionfile in our project directory
# install Python 3.11 if it does not exist
pyenv install 3.11
# switch versions globally
pyenv global 3.11
# set Python 3.11 locally for the current project/directory
pyenv local 3.11
# use shell specific versions
pyenv shell 3.11To check what Python versions are currently installed with pyenv “