PIP Python Package Installer#

pip is a package manager for Python. It’s a command-line tool that allows you to install, uninstall, and manage Python packages (libraries).

Key functions of pip:

  • Installation: Downloads and installs Python packages from the Python Package Index (PyPI) or other repositories.

  • Uninstallation: Removes installed packages from your system.

  • Listing: Displays a list of installed packages.

  • Search: Finds packages on PyPI based on keywords.

  • Update: Checks for and installs newer versions of installed packages.

Example usage:

To install the NumPy package:

Cmd/Powershell

pip install numpy

To uninstall the NumPy package:

Cmd/Powershell

pip uninstall numpy

To list all installed packages:

Cmd/Powershell

pip list

Note: Most Python distributions (like Anaconda or Miniconda) come with pip pre-installed. If you’re using a different distribution or need to install pip manually, you can follow the instructions on the official Python website.

Major pip Commands#

Here are some of the most common pip commands you’ll likely encounter:

Installation and Uninstallation#

  • pip install <package_name>:

    Installs a specific package from PyPI.

    • Example: pip install numpy

  • pip install -r requirements.txt: Installs all packages listed in a requirements.txt file.

  • pip uninstall <package_name>:

    Uninstalls a specific package.

    • Example: pip uninstall requests

Package Management#

  • pip list: Lists all installed packages.

  • pip show <package_name>: Displays detailed information about a package.

  • pip search <keyword>: Searches for packages on PyPI based on a keyword.

  • pip freeze: Generates a list of installed packages and their versions, often used to create a requirements.txt file.

Updating Packages#

  • pip install --upgrade <package_name>: Upgrades a specific package to the latest version.

  • pip install --upgrade -r requirements.txt: Upgrades all packages listed in a requirements.txt file.

Virtual Environments#

  • pip install virtualenv: Installs the virtualenv package to create isolated Python environments.

  • virtualenv <env_name>: Creates a new virtual environment.

  • source <env_name>/bin/activate: Activates the virtual environment.

  • deactivate: Deactivates the current virtual environment.

Additional Notes: