I will start with an example that will demonstrate how
pyenv works, and when you’re following along, you might not want to run these commands just yet because I will show you an even easier command to remove Python versions after this.
As mentioned before,
pyenv works by building Python from source, and each version that you have installed is located nicely in your
pyenv root directory. As you can see, I have already installed a couple of versions before this course, which I use for several projects I’m currently working on.
So, because all versions installed by
pyenv are located in the
~/.pyenv/versions/ directory and they are built from source, it is very trivial to remove them using the
And when we have another look at the contents of the
~/.pyenv/versions/ directory after running the
rm command, we can see that version 2.7.15 is indeed removed.
Now that you have seen where
pyenv stores the Python versions and you’ve learned the hard way to remove them, I’ve re-installed Python 2.7.15 and cleared my terminal to show you a much easier way to uninstall a Python version. When you are following along, this will be a good point to continue.
Just like any self-respecting dependency manager,
pyenv also has a built-in way to uninstall versions with the
pyenv uninstall command.
Instead of listing the
~/.pyenv/versions/ directory like you did before, you can also just use another
pyenv command. This will show all versions that are installed by
The asterisk (
*) indicates which Python version is active currently, which is
system Python. You might be wondering how
pyenv knows which Python version should be used.
You’ll be pleased to know there is no magic going on here because
pyenv simply sets the global Python version in a file that’s located at
As you might have noticed by now, you’re still using
system Python by default. This will also be confirmed when you run
python -v or when you have a look at which Python version you’re currently using.
This might be surprising, but this is how
pyenv inserts itself into your path and from your operating system’s perspective, that is the executable that is getting called.
If you want to see the actual path, you can run
pyenv which python.
In the next lesson, you will start to use the new Python version you have just installed with
Become a Member to join the conversation.
Michal on April 23, 2021
pyenv which pythondoesn’t work for me if system Python is set: