pip & Virtual Environments
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 install package_name = third-party library install karo
- requirements.txt = project dependencies ki list
- venv = isolated environment per-project — conflicts avoid karo
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())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"
]