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 arequirements.txtfile.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 arequirements.txtfile.
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 arequirements.txtfile.
Virtual Environments#
pip install virtualenv: Installs thevirtualenvpackage 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:
You can use the
-qflag to suppress output.For more advanced usage, refer to the official pip documentation: https://pypi.org/project/python-pip/