pip is the official package manager for Python. It allows you to install, update, and remove external libraries (packages) from the Python Package Index.

With pip, you can easily add powerful libraries to your Python projects without writing everything from scratch.

Example popular packages installed with pip:

  • NumPy – numerical computing
  • Pandas – data analysis
  • Requests – HTTP requests
  • Flask / Django – web development

πŸ”§ What is pip?

pip stands for β€œPip Installs Packages.”

It helps you:

βœ” Install new Python libraries
βœ” Upgrade existing packages
βœ” Remove packages
βœ” Manage project dependencies


πŸ“₯ Checking if pip is Installed

Most modern Python versions install pip automatically.

Check by running:

pip --version

Example output:

pip 24.0 from Python312

If pip is not installed:

python -m ensurepip --upgrade

πŸ“¦ Installing a Package

Use the following command:

pip install package_name

Example:

pip install requests

This installs the Requests library used for making HTTP requests.

Example Python code using it:

import requests

response = requests.get("https://example.com")
print(response.status_code)

⬆️ Upgrading a Package

To upgrade a package to the latest version:

pip install --upgrade package_name

Example:

pip install --upgrade requests

❌ Uninstalling a Package

To remove a package:

pip uninstall package_name

Example:

pip uninstall requests

πŸ“‹ Listing Installed Packages

To see all installed packages:

pip list

Example output:

Package      Version
------------ -------
requests 2.31.0
numpy 1.26.4

πŸ“„ Installing from requirements.txt

Projects often store dependencies in a requirements.txt file.

Example:

requests
numpy
pandas

Install all packages with:

pip install -r requirements.txt

πŸ” Searching for Packages

You can search for packages on the Python Package Index (PyPI) website.

Website:

https://pypi.org

Example packages:

  • requests
  • numpy
  • pandas
  • flask

🧠 Why pip is Important

Benefits:

βœ” Easy installation of libraries
βœ” Manages dependencies automatically
βœ” Access to thousands of packages
βœ” Essential for modern Python development


🧾 Example Workflow Using pip

Install libraries for a project:

pip install flask
pip install pandas
pip install matplotlib

Then import them in Python:

import flask
import pandas
import matplotlib

βœ… Summary

CommandPurpose
pip install packageInstall a package
pip uninstall packageRemove a package
pip listShow installed packages
pip install --upgrade packageUpgrade package
pip install -r requirements.txtInstall project dependencies