Skip to content

StopIteration error in trec_eval.py with Python 3.12 due to importlib.resources usage #2413

@zhihuat

Description

@zhihuat

Description

When running pyserini.eval.trec_eval on Python 3.12, a StopIteration error occurs. This is due to the way importlib.resources.files().joinpath('') behaves in Python 3.12, which seems to differ from previous versions or expects a different usage pattern.

Steps to Reproduce

Run any evaluation command using pyserini.eval.trec_eval in a Python 3.12 environment.

Example command:
python -m pyserini.eval.trec_eval -c -l 2 -m map dl19-passage run.msmarco-v1-passage.bge-base-en-v1.5.lucene-hnsw.onnx.dl19.txt

Traceback

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File ".../site-packages/pyserini/eval/trec_eval.py", line 45, in
jar_directory = str(importlib.resources.files("pyserini.resources.jars").joinpath(''))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../importlib/resources/readers.py", line 94, in joinpath
return super().joinpath(*descendants)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../importlib/resources/abc.py", line 117, in joinpath
target = next(names)
^^^^^^^^^^^
StopIteration

Environment

OS: Linux
Python: 3.12
Pyserini Version: 1.5.0

Proposed Fix

In pyserini/eval/trec_eval.py, line 45.

Current Code:

jar_directory = str(importlib.resources.files("pyserini.resources.jars").joinpath(''))

Fix:

Use the / operator to traverse the path, which is more robust and works correctly in Python 3.12.
jar_directory = str(importlib.resources.files("pyserini") / "resources" / "jars")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions