Master Python virtual environments and PIP to manage dependencies efficiently.
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.
# 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
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