# Python Ensurepip Module

The `ensurepip` module provides support for bootstrapping the `pip` installer into an existing Python installation or virtual environment. This bootstrapping approach reflects the fact that `pip` is an independent project with its own release cycle, and the latest available stable version is bundled with maintenance and regular releases of the CPython interpreter.

## Importing the Module

```python
import ensurepip
```

## Command Line Usage

The primary way to use `ensurepip` is from the command line.

### Basic Usage

To install `pip` into the current environment:

```bash
python -m ensurepip
```

### Upgrading pip

To ensure that the installed version of `pip` is at least as recent as the one bundled with `ensurepip`, pass the `--upgrade` or `-U` option:

```bash
python -m ensurepip --upgrade
```

### User Installation

To install `pip` into the user site-packages directory (useful if you don't have write permissions to the system Python installation):

```bash
python -m ensurepip --user
```

## Programmatic Usage

The `ensurepip` module also exposes a function to invoke it programmatically.

### `ensurepip.bootstrap()`

Bootstraps `pip` into the current or designated environment.

```python
import ensurepip

# Install pip if not present
ensurepip.bootstrap()
```

### `ensurepip.version()`

Returns a string specifying the bundled version of pip that will be installed.

```python
import ensurepip

print(ensurepip.version())
```

[[programming/python/python]]