Python Documentation

PIP

PIP (Package Installer for Python)

PIP is the standard package manager for Python. It allows you to install and manage additional packages that are not part of the Python standard library.

What is PIP?

PIP stands for "Pip Installs Packages" or "Pip Installs Python". It's a command-line tool that allows you to install, reinstall, and uninstall Python packages with ease.

Basic PIP Commands

Here are some of the most commonly used PIP commands:

# Install a package
pip install package_name

# Uninstall a package
pip uninstall package_name

# List installed packages
pip list

# Show package details
pip show package_name

# Search for packages
pip search search_term

# Upgrade a package
pip install --upgrade package_name

Installing PIP

PIP comes pre-installed with Python 2.7.9+ and Python 3.4+. If you need to install it manually:

  1. Download get-pip.py from https://bootstrap.pypa.io/get-pip.py
  2. Run the script: python get-pip.py

Using Requirements Files

You can use a requirements file to install multiple packages at once:

# Create a requirements.txt file
pip freeze > requirements.txt

# Install from requirements.txt
pip install -r requirements.txt

Best Practices

  • Always use virtual environments to isolate project dependencies
  • Keep your packages updated, but be cautious about breaking changes
  • Use version specifiers in your requirements file for consistency
  • Consider using pip-tools for more advanced dependency management

PIP is an essential tool for Python developers, making it easy to use and share code. Understanding how to use PIP effectively will greatly enhance your Python development experience.