{"record":{"id":"bc4fb35bb62f187d","repo":"ruvnet/RuView","slug":"nvs-partition-generator-not-available-install-pi","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":"firmware/esp32-csi-node/provision.py","lineNumber":276,"sourceCode":"                    return f.read()\n            except (subprocess.CalledProcessError, FileNotFoundError):\n                continue\n\n        # Method 2: ESP-IDF bundled script\n        idf_path = os.environ.get(\"IDF_PATH\", \"\")\n        gen_script = os.path.join(idf_path, \"components\", \"nvs_flash\",\n                                  \"nvs_partition_generator\", \"nvs_partition_gen.py\")\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        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 (csv_path, bin_path):\n            if os.path.isfile(p):\n                os.unlink(p)\n\n\ndef flash_nvs(port, baud, nvs_bin, chip):\n    \"\"\"Flash the NVS partition binary to the ESP32.\"\"\"\n    with tempfile.NamedTemporaryFile(suffix=\".bin\", delete=False) as f:\n        f.write(nvs_bin)\n        bin_path = f.name\n\n    try:\n        cmd = [","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/firmware/esp32-csi-node/provision.py#L258-L294","documentation":"provision.py's generate_nvs_binary() tries three ways to reach the ESP-IDF NVS partition generator: 'python -m esp_idf_nvs_partition_gen', 'python -m nvs_partition_gen', and the bundled script at $IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py. If none succeed, it raises RuntimeError instructing you to pip-install the generator. So neither the pip package is importable in the current interpreter nor is IDF_PATH set to a valid ESP-IDF checkout.","triggerScenarios":"Running 'provision.py' on a machine where the ESP-IDF environment was never sourced (no IDF_PATH) and the esp-idf-nvs-partition-gen package was not pip-installed; running in a venv that lacks the package even though another environment has it; ESP-IDF present but IDF_PATH unset or pointing to a moved/deleted directory.","commonSituations":"Fresh provisioning workstations; CI containers that install esptool but not the NVS generator; users who sourced export.sh in a different shell than the one running provision.py; IDF_PATH stale after moving the ESP-IDF folder.","solutions":["Install the generator into the interpreter that runs provision.py: 'pip install esp-idf-nvs-partition-gen'.","Alternatively source the ESP-IDF environment so the bundled script is found: '. ~/esp/esp-idf/export.sh' (sets IDF_PATH), then run provision.py in the same shell.","Verify one of the paths works: 'python -m esp_idf_nvs_partition_gen --help' or check that $IDF_PATH/components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py exists.","Confirm you are using the same virtualenv/interpreter used for provisioning (sys.executable is what invokes the module)."],"exampleFix":"# before\nnvs_bin = generate_nvs_binary(csv_content, 0x6000)  # RuntimeError: NVS partition generator not available\n\n# after\nimport importlib.util, os, sys\nhas_pkg = importlib.util.find_spec('esp_idf_nvs_partition_gen') is not None\nidf = os.environ.get('IDF_PATH', '')\nhas_idf = os.path.isfile(os.path.join(idf, 'components', 'nvs_flash',\n                                     'nvs_partition_generator', 'nvs_partition_gen.py'))\nif not (has_pkg or has_idf):\n    raise SystemExit('pip install esp-idf-nvs-partition-gen (or source ESP-IDF export.sh)')\nnvs_bin = generate_nvs_binary(csv_content, 0x6000)","handlingStrategy":"validation","validationCode":"import importlib.util, os\nhas_pkg = (importlib.util.find_spec('esp_idf_nvs_partition_gen') is not None\n           or importlib.util.find_spec('nvs_partition_gen') is not None)\nhas_idf = os.path.isfile(os.path.join(\n    os.environ.get('IDF_PATH', ''), 'components', 'nvs_flash',\n    'nvs_partition_generator', 'nvs_partition_gen.py'))\nif not (has_pkg or has_idf):\n    raise SystemExit('pip install esp-idf-nvs-partition-gen or source ESP-IDF export.sh')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add esp-idf-nvs-partition-gen to the provisioning requirements/venv so generate_nvs_binary always finds Method 1.","Run provision.py from a shell that sourced ESP-IDF's export.sh when relying on the bundled script (Method 2).","Preflight the environment (find_spec + IDF_PATH check) at the start of provisioning scripts, before any hardware interaction."],"tags":["esp32","nvs","firmware","provisioning","toolchain"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}