🐍 Virtual Environments & PIP in Python

Master Python virtual environments and PIP to manage dependencies efficiently.

🌐 What is a Virtual Environment?

Know more in Detail What are Dunder Methods

A virtual environment is a self-contained directory that contains a Python installation and separate libraries for a project. It allows you to manage project-specific dependencies without affecting global settings.

πŸš€ Why Use Virtual Environments?

πŸ› οΈ Creating a Virtual Environment

# Step 1: Install virtualenv (optional)
pip install virtualenv

# Step 2: Create environment
python -m venv myenv

# Step 3: Activate it
# Windows:
myenv\Scripts\activate
# macOS/Linux:
source myenv/bin/activate

# Step 4: Deactivate it
 deactivate

πŸ“¦ What is PIP?

PIP is Python’s built-in package manager. You can install packages like requests, flask, or numpy easily.

# Install a package
pip install requests

# Freeze current dependencies
pip freeze > requirements.txt

# Install from a requirements file
pip install -r requirements.txt

πŸ”— References