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.

Activating Multiple Environments Simultaneously

00:00 Let’s say you want to use the black and isort formatters for the bree project. Instead of adding those formatters to each project, I usually create a virtual environment specific for those tools and activate both that virtual environment and the actual project virtual environment.

00:22 So, let’s start by creating a virtual environment named formatters from Python 3.9.0, after which you can use pyenv shell formatters to activate the virtual environment, install black and install isort using pip,

00:48 and unset pyenv shell.

00:53 Let’s clear the screen and check pyenv version, which will show that you’re still in the bree virtual environment and when you run the black command, pyenv will tell you that this is not found in the bree virtual environment, but it is found in the formatters virtual environment.

01:20 So, how would you access black and isort while you’re working on the bree project? You could use the pyenv shell each time you want to run them, but there is an easier way. After all, this lesson is about activating multiple environments simultaneously.

01:43 So, let’s do that. While you are in the bree project directory, run pyenv local bree formatters. Now when you run black, you will see that it works just fine.

02:02 But how does this work? Well, when you take a look at the .python-version file, you will see that both bree and formatters is in there.

02:18 When a command is not found in the bree virtual environment, then pyenv will try to resolve it in the formatters virtual environment.

02:29 When the command is not found there either, like when you run a command called mordor, an error will be raised.

02:41 Now that you know how to work with multiple environments and Python versions in the same project, let’s do a wrap-up of this course in the next and final lesson.

Become a Member to join the conversation.