Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Installation Location

00:00 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.

00:17 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.

00:41 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 rm command.

01:01 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.

01:18 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.

01:42 Just like any self-respecting dependency manager, pyenv also has a built-in way to uninstall versions with the pyenv uninstall command.

01:58 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 pyenv.

02:14 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.

02:27 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 ~/.pyenv/version.

02:42 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.

02:57 This might be surprising, but this is how pyenv works. pyenv inserts itself into your path and from your operating system’s perspective, that is the executable that is getting called.

03:12 If you want to see the actual path, you can run pyenv which python.

03:21 In the next lesson, you will start to use the new Python version you have just installed with pyenv.

Michal on April 23, 2021

Interestingly, pyenv which python doesn’t work for me if system Python is set:

$ pyenv versions
* system (set by /home/michal/.pyenv/version)
$ cat ~/.pyenv/version
$ which python
$ pyenv which python
pyenv: python: command not found

The `python' command exists in these Python versions:

Note: See 'pyenv help global' for tips on allowing both
      python2 and python3 to be found.

Become a Member to join the conversation.