open-mmlab/mmdetection · error · RuntimeError

panopticapi is not installed, please install it by: pip inst

Error message

panopticapi is not installed, please install it by: pip install git+https://github.com/cocodataset/panopticapi.git.

What it means

pq_compute_single_core implements COCO panoptic quality computation and needs the official panopticapi library (PQStat). If the import failed, PQStat is None and RuntimeError is raised with install instructions.

Source

Thrown at mmdet/evaluation/functional/panoptic_utils.py:53

                           backend_args=None,
                           print_log=False):
    """The single core function to evaluate the metric of Panoptic
    Segmentation.

    Same as the function with the same name in `panopticapi`. Only the function
    to load the images is changed to use the file client.

    Args:
        proc_id (int): The id of the mini process.
        gt_folder (str): The path of the ground truth images.
        pred_folder (str): The path of the prediction images.
        categories (str): The categories of the dataset.
        backend_args (object): The Backend of the dataset. If None,
            the backend will be set to `local`.
        print_log (bool): Whether to print the log. Defaults to False.
    """
    if PQStat is None:
        raise RuntimeError(
            'panopticapi is not installed, please install it by: '
            'pip install git+https://github.com/cocodataset/'
            'panopticapi.git.')

    pq_stat = PQStat()

    idx = 0
    for gt_ann, pred_ann in annotation_set:
        if print_log and idx % 100 == 0:
            print('Core: {}, {} from {} images processed'.format(
                proc_id, idx, len(annotation_set)))
        idx += 1
        # The gt images can be on the local disk or `ceph`, so we use
        # backend here.
        img_bytes = get(
            os.path.join(gt_folder, gt_ann['file_name']),
            backend_args=backend_args)
        pan_gt = mmcv.imfrombytes(img_bytes, flag='color', channel_order='rgb')

View on GitHub (pinned to cfd5d3a985)

Solutions

  1. pip install git+https://github.com/cocodataset/panopticapi.git
  2. Verify: python -c "from panopticapi.evaluation import PQStat"
  3. Add the package to your environment/CI requirements when panoptic eval is used

Example fix

# before
pq_compute_single_core(...)  # RuntimeError
# after
# after installing panopticapi:
pq_compute_single_core(...)
Defensive patterns

Strategy: validation

Validate before calling

try:
    from panopticapi.evaluation import PQStat  # noqa
except ImportError:
    raise SystemExit('pip install git+https://github.com/cocodataset/panopticapi.git')

Try / catch

try:
    pq_compute_single_core(...)
except RuntimeError as e:
    if 'panopticapi' in str(e):
        raise SystemExit('Install panopticapi first')
    raise

Prevention

When it happens

Trigger: Running PanopticMetric / pq_compute_single_core without `pip install git+https://github.com/cocodataset/panopticapi.git`.

Common situations: Panoptic segmentation evaluation in minimal envs; panopticapi is not on PyPI in all versions so it's often missing from requirements.

Related errors


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