{"id":"dc611c7f51ce114f","repo":"pypa/pip","slug":"no-input-was-expected-pip-no-input-set-questio","errorCode":null,"errorMessage":"No input was expected ($PIP_NO_INPUT set); question: {message}","messagePattern":"No input was expected \\(\\$PIP_NO_INPUT set\\); question: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/utils/misc.py","lineNumber":253,"sourceCode":"    n = 1\n    extension = ext\n    while os.path.exists(dir + extension):\n        n += 1\n        extension = ext + str(n)\n    return dir + extension\n\n\ndef ask_path_exists(message: str, options: Iterable[str]) -> str:\n    for action in os.environ.get(\"PIP_EXISTS_ACTION\", \"\").split():\n        if action in options:\n            return action\n    return ask(message, options)\n\n\ndef _check_no_input(message: str) -> None:\n    \"\"\"Raise an error if no input is allowed.\"\"\"\n    if os.environ.get(\"PIP_NO_INPUT\"):\n        raise Exception(\n            f\"No input was expected ($PIP_NO_INPUT set); question: {message}\"\n        )\n\n\ndef ask(message: str, options: Iterable[str]) -> str:\n    \"\"\"Ask the message interactively, with the given possible responses\"\"\"\n    while 1:\n        _check_no_input(message)\n        response = input(message)\n        response = response.strip().lower()\n        if response not in options:\n            print(\n                \"Your response ({!r}) was not one of the expected responses: \"\n                \"{}\".format(response, \", \".join(options))\n            )\n        else:\n            return response\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/utils/misc.py#L235-L271","documentation":"A plain Exception raised by _check_no_input when PIP_NO_INPUT is set in the environment and pip needs to ask an interactive question (confirmation/deletion prompt). Setting PIP_NO_INPUT declares 'never prompt me'; pip honors that by failing instead of blocking on stdin, which is essential for non-interactive CI.","triggerScenarios":"os.environ.get('PIP_NO_INPUT') is truthy and ask()/ask_path_exists() is called — e.g. a target directory already exists and PIP_EXISTS_ACTION doesn't resolve it, or an uninstall needs to confirm deletion of files outside the prefix.","commonSituations":"CI/docker with PIP_NO_INPUT=1 (or PIP_NO_INPUT set globally) where pip hits a path-exists prompt because PIP_EXISTS_ACTION isn't set; uninstalling a package that installed files outside the tracked prefix; installing into a venv whose target dir conflicts.","solutions":["Set PIP_EXISTS_ACTION=a (or the relevant action: b/c/w/s) so pip never needs to ask about existing paths.","Pre-clean the target (rm the conflicting dir or uninstall first) so no prompt is needed.","If interactivity is actually fine, unset PIP_NO_INPUT and run in a TTY.","Pass the corresponding flag directly (e.g. --exists-action a) instead of relying on the env var."],"exampleFix":"# before\nexport PIP_NO_INPUT=1\npip install pkg   # hits 'target dir exists' prompt → Exception\n\n# after\nexport PIP_NO_INPUT=1\nexport PIP_EXISTS_ACTION=a\npip install pkg","handlingStrategy":"validation","validationCode":"import os\n\ndef ensure_noninteractive_safe(exists_action=None):\n    if os.environ.get('PIP_NO_INPUT') and not exists_action:\n        # set a default action so pip never blocks on a path-exists prompt\n        os.environ.setdefault('PIP_EXISTS_ACTION', 'a')\n# call before any pip invocation in CI","typeGuard":null,"tryCatchPattern":"try:\n    pip_install(pkg)\nexcept Exception as e:\n    if 'PIP_NO_INPUT set' in str(e):\n        os.environ['PIP_EXISTS_ACTION'] = 'a'\n        pip_install(pkg)\n    else:\n        raise","preventionTips":["Always set PIP_EXISTS_ACTION in CI alongside PIP_NO_INPUT.","Pre-clean target directories / uninstall conflicting packages before installing.","Pass --exists-action explicitly rather than relying on the env var."],"tags":["pip","interactive","environment","ci","pip-no-input"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}