Tutorials Logic
Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Tools
Online Compiler JSON Formatter Regex Tester CSS Unit Converter Color Picker
Compiler Tools

Python pip Tutorial - Install Packages, Virtual Environment

What is PIP?

PIP (Pip Installs Packages) is Python's package manager. It lets you install, update, and remove third-party libraries from PyPI (Python Package Index) - a repository of over 500,000 packages.

Basic PIP Commands

PIP Commands
# Check pip version
pip --version
pip3 --version

# Install a package
pip install requests
pip install numpy
pip install "flask==3.0.0"       # specific version
pip install "django>=4.0,<5.0"   # version range

# Install multiple packages
pip install requests flask numpy

# Upgrade a package
pip install --upgrade requests

# Uninstall a package
pip uninstall requests

# List installed packages
pip list

# Show package info
pip show requests

# Search for packages (deprecated in newer pip, use pypi.org)
pip search flask

requirements.txt

A requirements.txt file lists all project dependencies. This is the standard way to share and reproduce project environments.

requirements.txt
# Generate requirements.txt from current environment
pip freeze > requirements.txt

# Install all packages from requirements.txt
pip install -r requirements.txt

# Install with exact versions (reproducible)
pip install -r requirements.txt --no-deps
# requirements.txt example
requests==2.31.0
flask==3.0.0
numpy>=1.24.0
pandas>=2.0.0,<3.0.0
python-dotenv
pytest>=7.0

Virtual Environments

A virtual environment is an isolated Python environment for each project. This prevents package version conflicts between projects.

Virtual Environments
# Create a virtual environment
python -m venv venv

# Activate (Windows)
venv\Scripts\activate

# Activate (macOS/Linux)
source venv/bin/activate

# Your prompt changes to: (venv) $

# Now install packages - they go into venv only
pip install requests flask

# Deactivate when done
deactivate

# Delete the environment (just delete the folder)
rm -rf venv

Popular Python Packages

PackageCategoryDescription
requestsHTTPSimple HTTP requests
flaskWebLightweight web framework
djangoWebFull-featured web framework
fastapiWeb/APIModern async API framework
numpyData ScienceNumerical computing
pandasData ScienceData analysis and manipulation
matplotlibData ScienceData visualization
scikit-learnMLMachine learning algorithms
tensorflowML/AIDeep learning framework
pytestTestingTesting framework
sqlalchemyDatabaseSQL toolkit and ORM
pillowImagesImage processing
beautifulsoup4Web ScrapingHTML/XML parsing
python-dotenvConfigLoad .env files
Using requests
import requests

# GET request
response = requests.get("https://api.github.com/users/python")
print(response.status_code)   # 200
data = response.json()
print(data["name"])            # Python

# POST request
payload = {"username": "alice", "password": "secret"}
response = requests.post("https://httpbin.org/post", json=payload)
print(response.json())

# With headers and timeout
headers = {"Authorization": "Bearer TOKEN"}
response = requests.get(
    "https://api.example.com/data",
    headers=headers,
    timeout=10
)

# Error handling
try:
    response = requests.get("https://example.com", timeout=5)
    response.raise_for_status()   # raises for 4xx/5xx
    print(response.text)
except requests.exceptions.Timeout:
    print("Request timed out")
except requests.exceptions.HTTPError as e:
    print(f"HTTP error: {e}")

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.