On this page
  1. ensurepip
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Bootstrapping pip Inside a Fresh Virtual Environment
  7. Gotchas & Boundaries
  8. Common Functions

ensurepip

Prev: encodings | Up: stdlib_module | Next: enum
Rel: sys, sysconfig, builtins, warnings, dataclasses
Ref: docs.python.org — ensurepip
Tags: #public #python3 #stdlib


Import

import ensurepip

Overview

Bootstrapping module that installs the bundled version of pip into a Python environment (python3 -m ensurepip --upgrade or ensurepip.bootstrap()). Used automatically by venv when creating virtual environments, and handy when repairing an environment that was created with --without-pip.

Quick Start

import ensurepip

# Inspect the bundled pip version shipped with this Python installation
bundled_version = ensurepip.version()
assert isinstance(bundled_version, str) and "." in bundled_version

Implementation Walkthrough

1. Bootstrapping pip Inside a Fresh Virtual Environment

From the shell, run python3 -m ensurepip --upgrade (or pass --default-pip). Programmatically, ensurepip.bootstrap(upgrade=True, default_pip=True) installs the bundled wheel offline with zero network access.

Gotchas & Boundaries

Common Functions

Linked from

Related notes