Essential pip Commands for Python Package Management

Below is a list of commonly used pip commands for managing Python packages. pip is the package installer for Python, allowing you to install, update, and manage Python packages from the Python Package Index (PyPI) and other package indexes.

Basic pip Commands

  • Install a Package
  pip install package_name

Install a specific version of a package:

  pip install package_name==version
  • Upgrade a Package
  pip install --upgrade package_name
  • Uninstall a Package
  pip uninstall package_name
  • List Installed Packages
  pip list
  • Show Package Information
  pip show package_name
  • Check for Outdated Packages
  pip list --outdated

Managing Requirements

  • Generate a Requirements File
    This file typically contains a list of all packages needed for a project.
  pip freeze > requirements.txt
  • Install Packages from a Requirements File
  pip install -r requirements.txt

Using Different Python Versions

  • Specific Python Version
    If you have multiple versions of Python installed, you can specify which version of pip to use:
  python3.9 -m pip install package_name

Configuration and Cache Management

  • Configuring pip
    Access the pip configuration file:
  pip config list
  • Manage Cache
    Check cache info:
  pip cache list

Remove all items from the cache:

  pip cache purge

Using Wheels and Local Packages

  • Install a Wheel File
  pip install some-package.whl
  • Install from a Local Source Distribution
  pip install ./package_directory

These commands form the foundation of package management in Python, helping developers to maintain their development environments efficiently.

Hello, I’m Anuj. I make and teach software.

My website is free of advertisements, affiliate links, tracking or analytics, sponsored posts, and paywalls.
Follow me on LinkedIn, X (twitter) to get timely updates when I post new articles.
My students are the reason this website exists. ❤️

Feedback Display