On this page
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
- Does not fetch from PyPI:
ensurepipinstalls the local wheel bundled inside the stdlib; runpython3 -m pip install --upgrade pipafterward if you want the newest PyPI release. - Disabled in some Linux distro packages: Debian/Ubuntu split
ensurepipinto a separatepython3-venvapt package, so callingensurepipon a bare system Python may fail until that package is installed.
Common Functions
- ensurepip.bootstrap() —
bootstrap(*, root=None, upgrade=False, user=False, altinstall=False, default_pip=False, verbosity=0)— Bootstrap pip into the current Python installation (or the given root directory). - ensurepip.version() —
version()— Returns a string specifying the bundled version of pip.
Linked from
- tuts/python3/stdlib_module
- tuts/python3/stdlib_module/encodings
- tuts/python3/stdlib_module/ensurepip/bootstrap
- tuts/python3/stdlib_module/ensurepip/version
- tuts/python3/stdlib_module/enum
- tuts/python3/stdlib_module/stdlib_module
- tuts/python3/tutorials/intermediate_python_and_software_engineering/modules_packages_and_tooling
Related notes
- tuts/python3/stdlib_module/encodings Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ensurepip/bootstrap Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ensurepip/version Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/enum Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stdlib_module Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/builtins Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/dataclasses Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sys Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sysconfig Linked here; shared tags: #stdlib