# Python V2 with Docker (/scripting-v2/docker)



Market Lab reproduces your local Python environment inside Docker automatically. You do not need a Dockerfile or `requirements.txt`.

## Deploy [#deploy]

Install your packages in a virtual environment beside the script:

```bash
python3 -m venv .venv
.venv/bin/python -m pip install numpy pandas matplotlib
```

Select Docker and run the script:

```bash
mlab daemon backend docker

mlab script run strategy.py \
  --python .venv/bin/python
```

On the first deployment, Market Lab:

1. reads the Python version and installed packages from the selected environment;
2. creates an isolated Linux environment with the same pinned package versions; and
3. snapshots the strategy into the job directory before starting it.

Later jobs reuse that environment:

```text
Python runtime 394af2a3f753 reused (80 packages)
```

Changing only `strategy.py` does not reinstall packages. Changing Python or any installed package creates a new runtime.

## What is stored [#what-is-stored]

Managed environments live under:

```text
~/.market-lab/python-runtimes/<fingerprint>/
```

They survive daemon-container replacement because `~/.market-lab` is mounted into the container. Market Lab currently captures every package installed in the selected environment, so keep the strategy environment focused.

Packages must be pinned distributions available from a package index. Editable installs, local paths, and direct URL dependencies are rejected with a clear error.

## Backtests [#backtests]

Backtests run directly with the selected local interpreter and do not use `mlabd`:

```bash
mlab script backtest strategy.py \
  --python .venv/bin/python \
  --from 2026-07-15 \
  --to 2026-07-16
```

## Inspect a live job [#inspect-a-live-job]

```bash
mlab script status <JOB_ID>
mlab script logs <JOB_ID> --follow
```

The status shows the Python version, runtime fingerprint, and package count. Use only Python packages and strategy code you trust.
