Commonly Used Commands
As you know by now,
pyenv comes with a lot of built-in commands. In this lesson, we’ll go over the most important ones, starting with the
pyenv install command. You’ve already used the
install command in a previous lesson.
This command can be used to install a specific version of Python. As you have seen before, you can use
pyenv install --list, maybe with
grep, to list all versions that you can install with
pyenv. If you want to see all compilation output while installing, you can run
pyenv install with the
which command is helpful for determining the full path to a system executable. Because
pyenv works by using shims, this command allows you to see the full path to the executable
pyenv is running. For example, if you wanted to see where
pip is installed, you could run
pyenv which pip.
local command, on the other hand, is often used to set a project-specific Python version. So, let’s move into a project directory and set the version to CPython 3.8.7 for this project by running
pyenv local 3.8.7.
This command creates a
.python-version file in your current directory that contains the Python version for this project. If you have
pyenv active in your environment, this file will automatically activate or deactivate this version for you.
So when you check which Python version is used, you will see it is the one you just set with the
local command. Now, when you move out of the project directory and check the Python version again, you will see that the global Python version 3.9.1 is used.
In this lesson, you learned the most important
pyenv commands. You might also have noticed that the Python version can be set in a couple of ways, which we’ll explore further in the next lesson.
Become a Member to join the conversation.