{"id":24474,"library":"pytrec-eval","title":"pytrec_eval","description":"Python bindings for the trec_eval information retrieval evaluation tool, providing standard IR metrics like MAP, NDCG, P@k, etc. Supports Python 3+. Current version 0.5 is the latest stable release. Updates are infrequent.","status":"active","version":"0.5","language":"python","source_language":"en","source_url":"https://github.com/cvangysel/pytrec_eval","tags":["information-retrieval","evaluation","trec_eval","ranking"],"install":[{"cmd":"pip install pytrec-eval","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"note":"Standard import, no submodule.","symbol":"pytrec_eval","correct":"import pytrec_eval"}],"quickstart":{"code":"import pytrec_eval\n\nqrel = {\n    'q1': {\n        'd1': 1,\n        'd2': 0,\n    }\n}\n\nrun = {\n    'q1': {\n        'd1': 0.9,\n        'd2': 0.1,\n    }\n}\n\nevaluator = pytrec_eval.RelevanceEvaluator(qrel, {'map', 'ndcg'})\nresults = evaluator.evaluate(run)\nprint(results)","lang":"python","description":"Evaluate a run against qrels using MAP and NDCG."},"warnings":[{"fix":"Install trec_eval via system package manager or build from source, and ensure trec_eval is in PATH.","message":"trec_eval binary must be installed separately and on PATH. pytrec_eval does not ship the binary.","severity":"gotcha","affected_versions":"all"},{"fix":"Use str(query_id) and str(doc_id) when building qrel and run dictionaries.","message":"Input dictionaries must have string keys for query and document IDs. Integer keys may cause type errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to Python 3.","message":"Version 0.5 dropped Python 2 support. Older code using Python 2 will break.","severity":"breaking","affected_versions":">=0.5"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install trec_eval (e.g., apt install trec_eval on Debian/Ubuntu) and ensure LD_LIBRARY_PATH includes the library directory.","cause":"trec_eval C library not installed or not in library path.","error":"trec_eval: error while loading shared libraries: libtrec_eval.so: cannot open shared object file: No such file or directory"},{"fix":"Cast all IDs to strings: {str(qid): {str(docid): score}}","cause":"Query or document IDs are integers, but pytrec_eval expects string keys.","error":"TypeError: string indices must be integers"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}