-->

Python - PIP Part 4: Using PIP in Virtual Environments

When working on different Python projects, it’s a good practice to use virtual environments to isolate package dependencies. PIP works seamlessly within virtual environments, allowing you to manage project-specific libraries.

Example 1: Creating a Virtual Environment

To create a virtual environment, you can use the venv module:

python -m venv myenv

Example 2: Activating the Virtual Environment

On Windows:

myenv\Scripts\activate

On Mac/Linux:

source myenv/bin/activate

Example 3: Installing Packages in a Virtual Environment

Once the environment is activated, you can install packages as usual:

pip install requests

Explanation:

Using PIP inside virtual environments prevents version conflicts between projects, ensuring each project has its own dependencies.