📥
Modules & Packages

pip & Virtual Environments

Third-Party Packages Install Karna
💡 pip ek app store jaisa hai — third-party packages (jaise numpy, requests, flask) install karne ke liye. Virtual environment ek alag, isolated "room" hai har project ke liye, taaki ek project ke packages doosre project se conflict na karein.

pip Python ka package manager hai — pip install package_name se koi bhi third-party library install ho jaati hai (PyPI se, Python Package Index). requirements.txt file mein project ki saari dependencies list karke, pip install -r requirements.txt se sabko ek saath install kar sakte ho.

Virtual environment (venv) ek isolated Python installation hai per-project — har project apne alag packages/versions rakh sakta hai, bina globally conflict kiye. Ye bahut important best practice hai, especially jab multiple projects alag package versions chahte hon.

# Terminal commands:
# pip install requests           # ek package install karo
# pip install requests numpy      # multiple ek saath
# pip freeze > requirements.txt   # current packages ki list save karo
# pip install -r requirements.txt # sab ek saath install karo

# Virtual environment banana:
# python -m venv myenv
# source myenv/bin/activate    # activate (Mac/Linux)
# myenv\Scripts\activate       # activate (Windows)
# pip install requests          # ab sirf isi venv mein install hoga
📥
pip ek app store jaisa hai — third-party packages (jaise numpy, requests, flask) install karne ke liye. Virtual environment ek alag, isolated "room" hai har project ke liye, taaki ek project ke packages doosre project se conflict na karein.
1 / 2
⚡ Quick Recap
  • pip install package_name = third-party library install karo
  • requirements.txt = project dependencies ki list
  • venv = isolated environment per-project — conflicts avoid karo
On this page (2 subtopics)

Kuch bahut popular Python packages: requests (HTTP calls), numpy (numerical computing), pandas (data analysis), flask/django (web frameworks), pytest (testing). In sab ko pip se install karna padta hai — standard library mein nahi hain.

# pip install requests

import requests
response = requests.get("https://api.example.com/data")
print(response.status_code)
print(response.json())
💡Tip: requests library HTTP calls ke liye industry standard hai — Python ka built-in urllib bhi kaam karta hai, lekin requests ka API bahut zyada clean/friendly hai.

requirements.txt purana standard hai. Modern Python projects usually pyproject.toml use karte hain — project metadata, dependencies, aur build configuration ek hi jagah, standardized format mein.

# pyproject.toml (simplified):
[project]
name = "myapp"
version = "1.0.0"
dependencies = [
    "requests>=2.28",
    "flask>=2.0"
]
💡Tip: Naye projects shuru karte waqt pyproject.toml prefer karo — Python packaging ecosystem isi direction mein move kar raha hai, requirements.txt legacy projects mein zyada milta hai.