Pyenv Install and Select Multiple (global) Python Versions

In some scenarios you might have two (or more) different pieces of code in your source repository that may require different versions of Python to run. Like say 2.7 and 3.7 or 3.9 and 3.10. How can we make that happen with pyenv?

To make multiple Python versions available at the same time in your environment, first install them if you haven’t:

$ pyenv install 3.9.12
$ pyenv install 3.10.4

Then set (select) both the versions as global ones:

$ pyenv global 3.9.12 3.10.4
$ pyenv global
3.9.12
3.10.4

Now you will have both python3.9 and python3.10 available in your $PATH and python3 will point to the first version that you passed to pyenv global.

Leave a Reply

Your email address will not be published.