{"record":{"id":"7536e665f3a028b9","repo":"pallets/flask","slug":"the-environment-variable-variable-name-r-is-not","errorCode":null,"errorMessage":"The environment variable {variable_name!r} is not set and as such configuration could not be loaded. Set this variable and make it point to a configuration file","messagePattern":"The environment variable (.+?) is not set and as such configuration could not be loaded\\. Set this variable and make it point to a configuration file","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/flask/config.py","lineNumber":118,"sourceCode":"        self.root_path = root_path\n\n    def from_envvar(self, variable_name: str, silent: bool = False) -> bool:\n        \"\"\"Loads a configuration from an environment variable pointing to\n        a configuration file.  This is basically just a shortcut with nicer\n        error messages for this line of code::\n\n            app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])\n\n        :param variable_name: name of the environment variable\n        :param silent: set to ``True`` if you want silent failure for missing\n                       files.\n        :return: ``True`` if the file was loaded successfully.\n        \"\"\"\n        rv = os.environ.get(variable_name)\n        if not rv:\n            if silent:\n                return False\n            raise RuntimeError(\n                f\"The environment variable {variable_name!r} is not set\"\n                \" and as such configuration could not be loaded. Set\"\n                \" this variable and make it point to a configuration\"\n                \" file\"\n            )\n        return self.from_pyfile(rv, silent=silent)\n\n    def from_prefixed_env(\n        self, prefix: str = \"FLASK\", *, loads: t.Callable[[str], t.Any] = json.loads\n    ) -> bool:\n        \"\"\"Load any environment variables that start with ``FLASK_``,\n        dropping the prefix from the env key for the config key. Values\n        are passed through a loading function to attempt to convert them\n        to more specific types than strings.\n\n        Keys are loaded in :func:`sorted` order.\n\n        The default loading function attempts to parse values as any","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/config.py#L100-L136","documentation":"Config.from_envvar(variable_name) reads os.environ.get(variable_name). If the value is missing or empty (falsy) and silent is False, it raises RuntimeError telling you the named environment variable is not set and must point to a config file. This is the explicit-failure path; silent=True would return False instead.","triggerScenarios":"Calling app.config.from_envvar('APP_SETTINGS') when APP_SETTINGS is unset or empty in the environment and silent=False (the default). The variable must hold a filesystem path to a Python config file that from_pyfile will then load.","commonSituations":"Deploying without setting the settings env var; forgetting to export it in the shell or systemd unit; a .env file not loaded by python-dotenv before from_envvar runs; renaming the env var in code but not in deployment.","solutions":["Set the environment variable to an absolute path of a Python config file: export APP_SETTINGS=/etc/myapp/prod.py.","Pass silent=True and handle the False return value if the config file is optional.","Load your .env file (e.g. via python-dotenv) before calling from_envvar."],"exampleFix":"# before\napp.config.from_envvar('APP_SETTINGS')   # raises if unset\n\n# after\napp.config.from_envvar('APP_SETTINGS', silent=True)  # returns False if unset\n# or ensure it is set: export APP_SETTINGS=/etc/myapp/prod.py","handlingStrategy":"validation","validationCode":"import os\n\ndef env_config_present(var: str) -> bool:\n    val = os.environ.get(var)\n    return bool(val) and os.path.isfile(val)","typeGuard":"null","tryCatchPattern":"try:\n    app.config.from_envvar('APP_SETTINGS')\nexcept RuntimeError:\n    app.config.from_object('mypkg.default_settings')","preventionTips":["Set required env vars in your deployment manifest (systemd unit, Dockerfile, compose).","Load .env via python-dotenv at process start, before from_envvar runs."],"tags":["flask","config","environment","configuration"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}