Specifying Your Python Version
So, how do all these commands interact with one another? The resolution order looks like this.
pyenv starts to look for the
PYENV_VERSION environment variable, which is set with the
pyenv shell command.
PYENV_VERSION environment variable isn’t set, then
pyenv will check whether a
.python-version file is found in the current folder or one of the parent folders, which would have been created by the
pyenv local command.
Now let’s have a look in the terminal what this exactly looks like. Let’s start with the
pyenv version command. You will see that currently
system Python is used, which means that at this moment
pyenv doesn’t really do anything for us.
Let’s fix that with the
pyenv local command. Let’s move into the project directory, run
pyenv local 3.8.7 if you haven’t already done so in a previous lesson, and have another look at the output of
pyenv version. Here again,
pyenv indicates how it would resolve our
But what if you just want to experiment with another Python interpreter, for example, when you want to try some new features of a new dev release? Just run
pyenv shell 3.9-dev, which indicates you want to test
3.9-dev, and check the version.
In this lesson, you have learned how exactly
pyenv resolves the
python command. In the next lesson, we’ll have a look at another very powerful concept used by Python developers: virtual environments.
Become a Member to join the conversation.