open-mmlab/mmdetection · error · ImportError

Please run "pip install jsonlines" to install this package.

Error message

Please run "pip install jsonlines" to install this package.

What it means

DumpODVGResultsMetric.__init__ needs the `jsonlines` package to write results in the ODVG (object detection / visual grounding) jsonl format, and it guards the import — if jsonlines is None it raises ImportError telling you to pip install it. The metric is used to dump detections to .jsonl for grounding/VLM pipelines and cannot run without the writer.

Source

Thrown at mmdet/evaluation/metrics/dump_odvg_results.py:34

@METRICS.register_module()
class DumpODVGResults(BaseMetric):
    default_prefix: Optional[str] = 'pl_odvg'

    def __init__(self,
                 outfile_path,
                 img_prefix: str,
                 score_thr: float = 0.1,
                 collect_device: str = 'cpu',
                 nms_thr: float = 0.5,
                 prefix: Optional[str] = None) -> None:
        super().__init__(collect_device=collect_device, prefix=prefix)
        self.outfile_path = outfile_path
        self.score_thr = score_thr
        self.img_prefix = img_prefix
        self.nms_thr = nms_thr

        if jsonlines is None:
            raise ImportError('Please run "pip install jsonlines" to install '
                              'this package.')

    def process(self, data_batch: Any, data_samples: Sequence[dict]) -> None:
        for data_sample in data_samples:
            result = {}

            filename = data_sample['img_path']
            filename = filename.replace(self.img_prefix, '')
            if filename.startswith('/'):
                filename = filename[1:]
            result['filename'] = filename

            height = data_sample['ori_shape'][0]
            width = data_sample['ori_shape'][1]
            result['height'] = height
            result['width'] = width

            pred_instances = data_sample['pred_instances']

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. pip install jsonlines
  2. Verify in the training env: python -c "import jsonlines"
  3. Add jsonlines to your environment/Dockerfile requirements if you use ODVG dumping

Example fix

# before: ImportError in DumpODVGResultsMetric(...)
# after
pip install jsonlines
python -c 'import jsonlines; print(jsonlines.__version__)'
Defensive patterns

Strategy: validation

Validate before calling

try:
    import jsonlines  # noqa
    jsonlines_ok = True
except ImportError:
    jsonlines_ok = False
assert jsonlines_ok, 'pip install jsonlines before using DumpODVGResultsMetric'

Type guard

def odvg_dump_available() -> bool:
    try:
        import jsonlines  # noqa: F401
        return True
    except ImportError:
        return False

Try / catch

try:
    DumpODVGResultsMetric(...)
except ImportError as e:
    if 'jsonlines' in str(e):
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'jsonlines'])
        DumpODVGResultsMetric(...)
    else:
        raise

Prevention

When it happens

Trigger: Constructing DumpODVGResultsMetric in an env where `import jsonlines` failed; running configs for ODVG-style training data generation (e.g.蒸馏/grounding data dumps) on a base mmdet install that lacks the optional dependency.

Common situations: Fresh install from mmdet requirements (jsonlines is not included); new conda/docker env; CI running a dump job for the first time.

Related errors


AI-assisted analysis of open-mmlab/mmdetection@cfd5d3a985 (2026-08-27). Data as JSON: /api/errors/dae11e5d7a92d3dc. Report an issue: GitHub.