


venv argument passed to python tells it to run the venv module, and gives it the name of. This uses pyenv exec to run the python command, which will use Python 3.10.7 in our case. Now, let's create a virtual environment using pyenv: pyenv exec python -m venv. If you want to change the global Python version: pyenv global 3.10.7 python-version file in your current folder, which tells pyenv to use that Python version. You can select a local version with: pyenv local 3.10.7 The global version is used if no local version is selected. You can have a globally selected Python version, and then locally selected Python versions. You can see the currently-selected Python version with this command: pyenv versionĪnd you can see all versions (including the currently selected one) with: pyenv versions To install a Python version: pyenv install 3.10.7 So now you know, you can install from these versions (and again, reminder to update to see the most recently-added versions). This will show you a long output, which may contain things like the following. Once I've created a virtual environment using a specific Python version (which I get from pyenv), from then on I just activate the virtual environment to get that version, and I don't have to faff around with pyenv any more.įirst, see if the version of Python you want is available (you may have to update pyenv to see recent versions, which I do with brew update & brew upgrade pyenv): pyenv install -list The great thing about pyenv for me is that it just works, and I only use it at the very beginning of a project, to create a virtual environment. To install pyenv on MacOS, I've just gone for Homebrew: brew updateĪfter installing you'll have to add a few things to your shell, to configure it. Give it a read!Īs a note, for Windows I've often use the pyenv-win project, which has worked well for me. Their README file actually explains how it works and how to install it really well. So, pyenv to the rescue! This command-line tool will handle installing and running specific Python versions! Also it becomes really tricky to distinguish minor versions, such as python3.10.3 from python3.10.4. You end up with multiple Python executables in your PATH, such as python, python2, python3, python3.7, and so on. If you need to install multiple Python versions, going the ol' installer route isn't the best idea.

Some projects use older Python versions, and other projects must use a specific Python version. We get new features and performance improvements, but we don't always want to use the latest version for everything. As a Python developer, I install new Python versions when they come out.
