{"record":{"id":"259ed7d0edbb14d2","repo":"ruvnet/RuView","slug":"nvs-partition-generator-not-available-install-pi-259ed7","errorCode":null,"errorMessage":"NVS partition generator not available. Install: pip install esp-idf-nvs-partition-gen","messagePattern":"NVS partition generator not available\\. Install: pip install esp-idf-nvs-partition-gen","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scripts/generate_nvs_matrix.py","lineNumber":332,"sourceCode":"        idf_path = os.environ.get(\"IDF_PATH\", \"\")\n        gen_script = os.path.join(\n            idf_path, \"components\", \"nvs_flash\",\n            \"nvs_partition_generator\", \"nvs_partition_gen.py\"\n        )\n        if os.path.isfile(gen_script):\n            # Fixed interpreter/script plus an argv list (never a shell);\n            # csv_path/bin_path are private NamedTemporaryFile paths.\n            subprocess.check_call([  # nosemgrep: dangerous-subprocess-use-tainted-env-args\n                sys.executable, gen_script, \"generate\",\n                csv_path, bin_path, hex(size)\n            ])\n            with open(bin_path, \"rb\") as f:\n                return f.read()\n\n        print(\"ERROR: NVS partition generator tool not found.\", file=sys.stderr)\n        print(\"Install: pip install esp-idf-nvs-partition-gen\", file=sys.stderr)\n        print(\"Or set IDF_PATH to your ESP-IDF installation\", file=sys.stderr)\n        raise RuntimeError(\n            \"NVS partition generator not available. \"\n            \"Install: pip install esp-idf-nvs-partition-gen\"\n        )\n\n    finally:\n        for p in set((csv_path, bin_path)):\n            if os.path.isfile(p):\n                os.unlink(p)\n\n\ndef main():\n    parser = argparse.ArgumentParser(\n        description=\"Generate NVS partition binaries for QEMU firmware test matrix (ADR-061)\",\n    )\n    parser.add_argument(\n        \"--output-dir\", required=True,\n        help=\"Directory to write NVS binary files\",\n    )","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/scripts/generate_nvs_matrix.py#L314-L350","documentation":"scripts/generate_nvs_matrix.py builds an NVS partition image for the ESP32 firmware. It tries three strategies in order: `python -m esp_idf_nvs_partition_gen generate`, a direct import of nvs_partition_gen (older API), and the script bundled in ESP-IDF at $IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py. This RuntimeError is raised only after all three fail, meaning no NVS generator is reachable from the interpreter running the script.","triggerScenarios":"None of: the esp-idf-nvs-partition-gen pip package importable by sys.executable, the legacy nvs_partition_gen module, or a valid IDF_PATH pointing at an ESP-IDF checkout. Note the subprocess calls use sys.executable, so the package must be installed in the same interpreter/venv that runs the script.","commonSituations":"Fresh CI container without the pip package; the package installed into a different virtualenv than the one running the script; IDF_PATH unset or pointing to an old/moved ESP-IDF directory that lacks the nvs_partition_generator script.","solutions":["Install the generator into the same interpreter: `python -m pip install esp-idf-nvs-partition-gen` (run with the venv active that you use for the script)","Or point at an ESP-IDF checkout: `export IDF_PATH=/path/to/esp-idf` so components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py resolves","Verify the module is reachable: `python -m nvs_partition_gen --help` (or -m esp_idf_nvs_partition_gen) — if that fails, the script will too","In CI, add the pip install step before invoking generate_nvs_matrix.py"],"exampleFix":"# before\npython scripts/generate_nvs_matrix.py  # RuntimeError: NVS partition generator not available\n\n# after\npython -m pip install esp-idf-nvs-partition-gen\npython scripts/generate_nvs_matrix.py","handlingStrategy":"validation","validationCode":"import importlib.util, os\n\ndef nvs_gen_available() -> bool:\n    if importlib.util.find_spec(\"esp_idf_nvs_partition_gen\") or importlib.util.find_spec(\"nvs_partition_gen\"):\n        return True\n    idf = os.environ.get(\"IDF_PATH\", \"\")\n    return os.path.isfile(os.path.join(idf, \"components\", \"nvs_flash\", \"nvs_partition_generator\", \"nvs_partition_gen.py\"))","typeGuard":null,"tryCatchPattern":"try:\n    blob = build_nvs_partition(...)  # however you wrap the script\nexcept RuntimeError as e:\n    raise SystemExit(f\"environment missing NVS tooling: {e}\") from e","preventionTips":["Pin `pip install esp-idf-nvs-partition-gen` in the CI job or requirements before firmware artifact generation","Install the package into the same venv/interpreter that runs the script (the script shells out via sys.executable)","Export IDF_PATH in the environment when relying on an ESP-IDF checkout"],"tags":["esp-idf","esp32","nvs","firmware","dependencies","python","scripts","environment"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}