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
Once you have installed a couple of versions, you can use the
pyenv versions command to display all of the currently installed Python versions, including system Python.
If you only care about the version that is currently activated, you can run
pyenv version, which is similar to
pyenv versions but only shows you the current active Python version.
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.
The output displays the full system path for
pip. This can be useful when you’ve installed command-line applications.
global command is yet another command you’ve already seen in a previous lesson, which is very useful for setting the default global Python version.
You will learn how to override the global Python versions for each of your projects in a minute. So, when you want to set the global Python version to 3.9.1, then just run
pyenv global 3.9.1.
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.
shell command is used to set a shell-specific Python version. For example, if you wanted to test out a
3.9-dev version of Python, you can just install it and next run
pyenv shell 3.9-dev.
This command activates the version specified by setting the
PYENV_VERSION environment variable. This command overrides any application or global settings you may have.
If you want to deactivate the version, you can use the
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.