> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lagerdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pip

> Manage Python packages in Lager Box containers

Install, list, and manage Python packages in the Lager Box Python container.

## Syntax

```bash theme={null}
lager pip COMMAND [OPTIONS]
```

## Commands

| Command     | Description                                   |
| ----------- | --------------------------------------------- |
| `install`   | Install packages into the Python container    |
| `list`      | List user-installed packages                  |
| `uninstall` | Uninstall packages from the container         |
| `apply`     | Apply package changes by rebuilding container |

***

## Command Reference

### `install`

Install Python packages persistently into the Lager Box container.

```bash theme={null}
lager pip install PACKAGES... [OPTIONS]
```

**Arguments:**

* `PACKAGES` - One or more package names (with optional version specifiers)

**Options:**

* `--box BOX` - Lagerbox name or IP address
* `--yes` - Skip confirmation and rebuild immediately

**Examples:**

```bash theme={null}
# Install a single package
lager pip install numpy --box lab-lager-box --yes

# Install multiple packages
lager pip install pandas scipy matplotlib --box lab-lager-box

# Install specific versions
lager pip install 'requests==2.28.0' 'flask>=2.0' --box lab-lager-box
```

### `list`

List user-installed packages on a Lager Box.

```bash theme={null}
lager pip list --box BOX
```

Output:

```
User-installed packages on lab-lager-box:
  numpy==1.24.0
  pandas==2.0.0
  requests==2.28.0
```

### `uninstall`

Remove packages from the Lager Box container.

```bash theme={null}
lager pip uninstall PACKAGES... [OPTIONS]
```

**Arguments:**

* `PACKAGES` - One or more package names to remove

**Options:**

* `--box BOX` - Lagerbox name or IP address
* `--yes` - Skip confirmation and rebuild immediately

**Examples:**

```bash theme={null}
# Uninstall a package
lager pip uninstall old-package --box lab-lager-box --yes

# Uninstall multiple packages
lager pip uninstall pkg1 pkg2 pkg3 --box lab-lager-box
```

### `apply`

Apply pending package changes by rebuilding the container.

```bash theme={null}
lager pip apply --box BOX [--yes]
```

This is useful when you've installed packages without `--yes` and want to apply changes later.

***

## How It Works

1. **Package Validation**: Packages are validated against PyPI before installation
2. **Requirements File**: Packages are added to `user_requirements.txt` on the Lager Box
3. **Container Rebuild**: Container is rebuilt with new packages (no-cache)
4. **Persistence**: Packages persist across container restarts

***

## Version Specifiers

Standard pip version specifiers are supported:

| Specifier | Example          | Description        |
| --------- | ---------------- | ------------------ |
| `==`      | `numpy==1.24.0`  | Exact version      |
| `>=`      | `flask>=2.0`     | Minimum version    |
| `<=`      | `requests<=2.28` | Maximum version    |
| `~=`      | `django~=4.0`    | Compatible release |
| (none)    | `pandas`         | Latest version     |

***

## Package Storage

User packages are stored at:

```
/home/www-data/box/python/docker/user_requirements.txt
```

This file is used during container builds to install user packages.

***

## Deferred Rebuild

If you don't use `--yes`, packages are queued for installation:

```bash theme={null}
# Queue packages
lager pip install numpy pandas --box lab-gw

# Later, apply changes
lager pip apply --box lab-gw --yes
```

***

## Examples

```bash theme={null}
# Set up a Lager Box with data science packages
lager pip install numpy pandas scipy matplotlib seaborn --box lab-lager-box --yes

# Add a specific version
lager pip install 'scikit-learn==1.2.0' --box lab-lager-box --yes

# Check what's installed
lager pip list --box lab-lager-box

# Clean up unused packages
lager pip uninstall unused-package --box lab-lager-box --yes
```

***

## Package Name Normalization

Package names are normalized to handle variations:

* `scikit-learn` and `scikit_learn` are treated the same
* Duplicates are automatically detected and skipped

***

## PyPI Validation

Before installation, packages are validated:

```
Validating packages against PyPI...
  [OK] numpy (found)
  [OK] pandas (found)
  [FAIL] nonexistent-pkg (not found on PyPI)

Error: Some packages not found on PyPI
```

***

## Notes

* Container rebuild uses `--no-cache` for fresh builds
* Rebuild can take several minutes depending on packages
* Use `lager pip list` to verify installation
* Pre-installed packages (in base image) are not shown in list
* Container restart happens automatically after rebuild
