Working With Multiple Environments
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 supports Python 3.8.7 and
the-shire supports Python 3.9.0.
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
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,
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.
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.