Switching Between Projects
One of the main reasons for using virtual environments is to easily switch between different projects with different dependencies.
Let's simulate this scenario. Assume you have two projects, project_a
and project_b
, each with its own virtual environment.
First, let's create a directory for project_a
and its virtual environment.
mkdir project_a
cd project_a
python3 -m venv venv_a
Now, activate the virtual environment for project_a
:
source venv_a/bin/activate
You should see (venv_a)
in your terminal prompt.
Now, let's create a directory for project_b
and its virtual environment. First, deactivate the current environment and navigate back to the project root directory.
deactivate
cd ..
mkdir project_b
cd project_b
python3 -m venv venv_b
Now, activate the virtual environment for project_b
:
source venv_b/bin/activate
You should see (venv_b)
in your terminal prompt.
By following this pattern of deactivating the current environment and then activating the desired environment, you can seamlessly switch between projects without any dependency conflicts.