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 see our video player troubleshooting guide to resolve the issue.

Working With Multiple Environments

00:00 Putting everything you’ve learned together, you can work effectively with multiple environments. Let’s assume you have the following versions installed. Now you want to work on two different projects named bree and the-shire. bree supports Python 3.8.7 and the-shire supports Python 3.9.0.

00:27 You can see that by default you are using the system Python, which is indicated by the asterisk (*) in the Python versions output. First, let’s move into the workspace/ directory, create a new directory for the bree project, move into this directory, create a virtual environment as we have learned in the previous lesson, which we’ll also name bree, and set the local interpreter for the bree project.

01:04 Once you’ve done these steps, the bree project is ready to go. So, let’s clear the screen, move back into the workspace/ directory, and create another folder for the the-shire project.

01:21 Next, we’ll create another virtual environment for the-shire by moving into the project directory, checking the currently activated Python version, which is system Python, create a new virtual environment,

01:40 and set the local interpreter to this new environment.

01:48 Now that you have configured the environments for each project, switching between them will be a breeze, as the virtual environments will automatically activate when you move into the project directories. At this moment, we’re still in the the-shire project, which uses the eponymous virtual environment.

02:10 So, let’s clear the screen again, move out of this project and back into the bree project, where you will see that it uses the bree virtual environment.

02:26 So, no more remembering to activate environments. You can switch between all your projects and pyenv will take care of automatically activating the correct Python versions and the correct virtual environments. In the next lesson, we’ll have a look at activating multiple environments simultaneously.

Become a Member to join the conversation.