Python PIP

Learn to install and manage Python packages easily

📦 Package Management

PIP (Pip Installs Packages) is the standard package manager for Python. It allows you to install, update, and manage Python packages from the Python Package Index (PyPI) and other repositories.


# Check pip version
pip --version

# Install a package
pip install requests

# Uninstall a package  
pip uninstall requests

# List installed packages
pip list

# Show package details
pip show requests
                                    
400K+
Packages
Built-in
Tool
Easy
Management

What is PIP?

📦

Package Installer

Install Python packages from PyPI

PyPI Dependencies
🔄

Version Management

Handle different package versions

Upgrade Downgrade
📋

Requirements

Manage project dependencies

requirements.txt Reproducible
🌐

Global Access

Access to millions of packages

Open Source Community

Checking PIP Installation

PIP comes pre-installed with Python 3.4+ and Python 2.7.9+. Let's verify your installation:

Check PIP Version
# Check PIP version
pip --version

# Alternative commands
pip -V
python -m pip --version

# On some systems, you might need to use pip3
pip3 --version
Expected Output:

You should see something like: pip 23.3.1 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)

What if it doesn't work?

Try typing pip3 --version instead. Some computers need "pip3" instead of just "pip".

Step 2: Install Your First Package

Let's install a popular package called "requests" that helps you download web pages:

Install the requests package
# Install the requests package
pip install requests

# You'll see output like:
# Collecting requests
# Installing collected packages: requests
# Successfully installed requests-2.31.0
Test the package you just installed
# Create a simple Python file to test
import requests

# Get a web page
response = requests.get('https://httpbin.org/json')
print("Status code:", response.status_code)
print("Content:", response.json())

# This will print:
# Status code: 200
# Content: {'slideshow': {'author': 'Yours Truly', ...}}

Step 3: Essential PIP Commands

Here are the most important commands you'll use every day:

📥 Install a Package

# Install any package
pip install package_name

# Example: Install colorama for colored text
pip install colorama

Downloads and installs a package from the internet

📋 List Packages

# List all installed packages
pip list

# You'll see something like:
# Package    Version
# ---------- -------
# requests   2.31.0
# colorama   0.4.6

Shows all packages currently installed

🔍 Get Package Info

# Get details about a package
pip show requests

# Shows:
# Name: requests
# Version: 2.31.0
# Summary: Python HTTP for Humans.

Shows detailed information about a package

🗑️ Remove a Package

# Uninstall a package you don't need
pip uninstall colorama

# It will ask: Proceed (Y/n)? 
# Type 'y' and press Enter

Removes a package you no longer need

Step 4: Try Some Fun Packages

Let's install and try some interesting packages to see what PIP can do:

Install and use colorama for colored text
# First, install colorama
pip install colorama
# Then try this Python code
from colorama import Fore, Style, init

# Initialize colorama
init()

print(Fore.RED + "This text is red!")
print(Fore.GREEN + "This text is green!")
print(Fore.BLUE + "This text is blue!")
print(Style.BRIGHT + "This text is bright!")
print(Style.RESET_ALL + "Back to normal text")
Install emoji package for fun symbols
# Install emoji package
pip install emoji
# Use emojis in your code
import emoji

print(emoji.emojize("I love Python! :snake:"))
print(emoji.emojize("Great job! :thumbs_up:"))
print(emoji.emojize("Pizza time! :pizza:"))

Step 5: Save Your Package List

When you work on projects, you'll want to remember which packages you used:

Create a requirements file
# Save all your packages to a file
pip freeze > requirements.txt

# This creates a file called requirements.txt with content like:
# requests==2.31.0
# colorama==0.4.6
# emoji==2.8.0
Install packages from requirements file
# Install all packages from the file
pip install -r requirements.txt

# This installs everything listed in requirements.txt
# Useful when sharing projects with friends!

Practice Project: Weather App

Let's build a simple weather app using packages from PIP:

Install required packages
# Install packages for our weather app
pip install requests colorama
Simple weather app code
import requests
from colorama import Fore, Style, init

# Initialize colorama for colored text
init()

def get_weather():
    """Get weather information for a city"""
    city = input("Enter a city name: ")
    
    # Using a free weather API (no key needed for demo)
    url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid=demo"
    
    try:
        response = requests.get(url)
        if response.status_code == 200:
            print(Fore.GREEN + f"✅ Weather data found for {city}!")
        else:
            print(Fore.RED + f"❌ Could not find weather for {city}")
    except:
        print(Fore.YELLOW + "⚠️ Could not connect to weather service")
    
    print(Style.RESET_ALL)  # Reset colors

# Run the weather app
if __name__ == "__main__":
    print(Fore.BLUE + "🌤️ Simple Weather App")
    print(Style.RESET_ALL)
    get_weather()

Common Issues and Solutions

🚫 "pip is not recognized"

Problem: Your computer can't find PIP

# Try these alternatives:
python -m pip --version
python3 -m pip --version
py -m pip --version

🔒 Permission Denied

Problem: You don't have permission to install

# Install just for your user account
pip install --user package_name

# Example:
pip install --user requests

🐌 Installation is Slow

Problem: Downloads are taking too long

# Clear the cache and try again
pip cache purge
pip install package_name

🧠 Test Your Knowledge

What command installs a package?

What does 'pip list' do?

What file saves your package list?