{"record":{"id":"2a3572c53a51e94c","repo":"pypa/pip","slug":"needed-a-specific-file-to-be-modifying","errorCode":null,"errorMessage":"Needed a specific file to be modifying.","messagePattern":"Needed a specific file to be modifying\\.","errorType":"exception","errorClass":"ConfigurationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/configuration.py","lineNumber":239,"sourceCode":"            ensure_dir(os.path.dirname(fname))\n\n            # Ensure directory's permission(need to be writeable)\n            try:\n                with open(fname, \"w\") as f:\n                    parser.write(f)\n            except OSError as error:\n                raise ConfigurationError(\n                    f\"An error occurred while writing to the configuration file \"\n                    f\"{fname}: {error}\"\n                )\n\n    #\n    # Private routines\n    #\n\n    def _ensure_have_load_only(self) -> None:\n        if self.load_only is None:\n            raise ConfigurationError(\"Needed a specific file to be modifying.\")\n        logger.debug(\"Will be working with %s variant only\", self.load_only)\n\n    @property\n    def _dictionary(self) -> dict[str, dict[str, Any]]:\n        \"\"\"A dictionary representing the loaded configuration.\"\"\"\n        # NOTE: Dictionaries are not populated if not loaded. So, conditionals\n        #       are not needed here.\n        retval = {}\n\n        for variant in OVERRIDE_ORDER:\n            retval.update(self._config[variant])\n\n        return retval\n\n    def _load_config_files(self) -> None:\n        \"\"\"Loads configuration from configuration files\"\"\"\n        config_files = dict(self.iter_config_files())\n        if config_files[kinds.ENV][0:1] == [os.devnull]:","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/configuration.py#L221-L257","documentation":"Raised by Configuration._ensure_have_load_only() (called by set_value, unset_value, and save) when self.load_only is None. Mutating operations require knowing which configuration layer/file to edit, so pip refuses to proceed without an explicit --user/--global/--site selection.","triggerScenarios":"Calling `pip config set <key> <value>` without specifying --user, --global, or --site; programmatically calling set_value/unset_value/save on a Configuration constructed with load_only=None.","commonSituations":"Forgetting the scope flag on `pip config set`/`unset`; scripts that call the Configuration API directly without a load_only.","solutions":["Specify the scope: `pip config set --global global.index-url ...` or --user or --site.","If using the API, construct Configuration with load_only set to one of kinds.USER/GLOBAL/SITE.","For read-only inspection no scope is needed; only set/unset/save require it."],"exampleFix":"# before\npip config set global.index-url https://...   # no scope\n# after\npip config set --global global.index-url https://...","handlingStrategy":"validation","validationCode":"def require_scope_flag(scope: str | None) -> str:\n    if scope not in ('--user', '--global', '--site'):\n        raise ValueError('pip config set/unset requires one of --user, --global, --site')\n    return scope\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a scope flag to pip config set/unset.","When using the API, set load_only explicitly."],"tags":["pip","config","configuration","scope","cli"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}