CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pip

The PyPA recommended tool for installing Python packages.

Overall
score

91%

Overview
Eval results
Files

index.mddocs/

Pip

The PyPA recommended tool for installing Python packages. Pip is the standard package manager for Python that installs packages from the Python Package Index (PyPI) and other repositories. It provides comprehensive package management capabilities including installation, uninstallation, dependency resolution, and package information queries.

IMPORTANT: Pip is designed as a command-line tool only and explicitly provides no public Python API for programmatic use. All functionality must be accessed through the CLI interface or subprocess calls.

Package Information

  • Package Name: pip
  • Package Type: Command-line tool
  • Language: Python
  • Installation: Comes pre-installed with Python 3.4+ and Python 2.7.9+
  • Entry Points: pip, pip3, python -m pip

Core Usage

Command Invocation

# Direct command usage
pip [command] [options]
pip3 [command] [options]

# Module execution
python -m pip [command] [options]

Programmatic Usage (Recommended)

Since pip provides no public Python API, use subprocess for programmatic package management:

import subprocess
import sys

# Install a package
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'requests'])

# Uninstall a package
subprocess.check_call([sys.executable, '-m', 'pip', 'uninstall', 'requests', '-y'])

# List installed packages
result = subprocess.run([sys.executable, '-m', 'pip', 'list'], 
                       capture_output=True, text=True)
print(result.stdout)

Basic Usage

# Install packages
pip install package_name
pip install package_name==1.2.3
pip install -r requirements.txt
pip install git+https://github.com/user/repo.git

# Uninstall packages
pip uninstall package_name
pip uninstall -r requirements.txt

# List installed packages
pip list
pip list --outdated

# Show package information
pip show package_name

# Generate requirements file
pip freeze > requirements.txt

# Upgrade packages
pip install --upgrade package_name
pip install --upgrade-strategy eager -r requirements.txt

Architecture

Pip follows a command-based architecture where each operation is handled by a specific command class:

  • CLI Layer: Command-line interface parsing and main entry point
  • Command Layer: Individual command implementations (install, uninstall, list, etc.)
  • Resolution Layer: Dependency resolution and conflict handling
  • Network Layer: Package downloading and repository interaction
  • Cache Layer: Wheel cache management and optimization
  • VCS Layer: Version control system integration (git, svn, etc.)

All implementation details are contained within the pip._internal.* namespace and are explicitly marked as private APIs subject to change without notice.

Capabilities

Package Installation

Install Python packages from PyPI, version control systems, local files, and other sources with comprehensive dependency resolution and conflict handling.

# Basic installation
pip install package_name

# Install specific version
pip install package_name==1.2.3

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

# Install from git repository
pip install git+https://github.com/user/repo.git

# Install in development mode
pip install -e .

Package Installation

Package Management

Uninstall packages, list installed packages, show package information, and manage package metadata with comprehensive querying capabilities.

# Uninstall packages
pip uninstall package_name

# List packages
pip list
pip list --outdated

# Show package details
pip show package_name

# Check for dependency conflicts
pip check

Package Management

Package Building and Distribution

Build wheels, compute package hashes, and manage distribution formats for package development and deployment workflows.

# Build wheels
pip wheel .
pip wheel -r requirements.txt

# Compute package hashes
pip hash package.tar.gz

# Download without installing
pip download package_name

Package Building

Configuration and Environment

Manage pip configuration, inspect Python environment information, handle caching, and configure package indexes for customized package management workflows.

# Configuration management
pip config list
pip config set global.index-url https://pypi.org/simple/

# Environment inspection
pip inspect

# Cache management
pip cache info
pip cache purge

# Index operations
pip index versions package_name

# Help and completion
pip help
pip completion --bash

Configuration

API Policy

Pip explicitly provides no public Python API. From the official documentation:

"pip is a command line program. While it is implemented in Python, and so is available from your Python code via import pip, you must not use pip's internal APIs in this way."

Key points:

  • All internal APIs can change at any time without notice
  • Pip assumes sole control of global program state
  • Issues from unsupported programmatic usage generally won't be fixed
  • Even the import name pip is subject to change

Semi-Public Elements (Import at Your Own Risk)

# Version information (most stable import)
import pip
print(pip.__version__)  # "24.3.1"

# Deprecated main function (internal use only)
from pip import main  # DO NOT USE - for console scripts only

Alternative Libraries

For programmatic package management needs, consider these alternatives:

  • subprocess: Official recommendation for calling pip programmatically
  • pip-tools: Dependency resolution and requirements management
  • importlib.metadata: Package metadata access (Python 3.8+)
  • pkg_resources: Legacy package metadata (deprecated)
  • packaging: Version parsing and specifier handling
  • distlib: Low-level distribution utilities

Error Handling

Pip exits with non-zero status codes on errors:

import subprocess
import sys

try:
    subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'nonexistent-package'])
except subprocess.CalledProcessError as e:
    print(f"Pip command failed with exit code {e.returncode}")
    print(f"Command: {' '.join(e.cmd)}")

Common exit codes:

  • 0: Success
  • 1: General error
  • 2: Command parsing error

Install with Tessl CLI

npx tessl i tessl/pypi-pip

docs

building.md

configuration.md

index.md

installation.md

management.md

tile.json