Python bootstrapping the pip installer

In addition to the modules and packages built in to the standard distribution of Python, large number of packages from third party developers are uploaded to Python package repository called Python Package Index ( To install packages from here, pip utility is needed. The pip tool is an independent project, but since Python 3.4, it has been bootstrapped in Python distribution.

The ensurepip module provides support for bootstrapping pip in existing installation of Python. Normally user doesn't need to use it explicitly. If however, installation of pip is skipped in normal installation or virtual environment, it may be needed.

Following command will create a virtual environment without pip utility being installed.

C:\python37>python -m venv --without-pip e:\testenv

The scripts folder under the virtual environment directory doesn't contain pip utility. The ensurepip module is now used to incorporate pip in it using its version in system wide installation. Specify '--upgrade' for its latest version

E:\testenv>scripts\python -m ensurepip --upgrade
Looking in links: C:\Users\acer\AppData\Local\Temp\tmpp1bb2lym
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-18.1 setuptools-40.6.2

Default installation of pip can be modified by following options

  • --root <dir> − Installs pip relative to the given root directory rather than the root of the currently active virtual environment (if any) or the default root for the current Python installation.

  • --user − Installs pip into the user site packages directory rather than globally for the current Python installation (this option is not permitted inside an active virtual environment).

The ensurepip module also defined following functions

  • ensurepip.version()  − Returns a string specifying the bundled version of pip that will be installed when bootstrapping an environment.

  • ensurepip.bootstrap() − Bootstraps pip into the current or designated environment.

The bootstrapping process has side effects on both sys.path and os.environ. Also, the bootstrapping process may install additional modules required by pip, but other software should not assume those dependencies will always be present by default

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started