{"id":"7a65899c14048cef","repo":"pypa/pip","slug":"could-not-open-kind-file-exc","errorCode":null,"errorMessage":"Could not open {kind} file: {exc}","messagePattern":"Could not open (.+?) file: (.+?)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/req/req_file.py","lineNumber":589,"sourceCode":"    :param session:     PipSession instance.\n    \"\"\"\n    scheme = urllib.parse.urlsplit(url).scheme\n    # Pip has special support for file:// URLs (LocalFSAdapter).\n    if scheme in [\"http\", \"https\", \"file\"]:\n        # Delay importing heavy network modules until absolutely necessary.\n        from pip._internal.network.utils import raise_for_status\n\n        resp = session.get(url)\n        raise_for_status(resp)\n        return resp.url, resp.text\n\n    # Assume this is a bare path.\n    try:\n        with open(url, \"rb\") as f:\n            raw_content = f.read()\n    except OSError as exc:\n        kind = \"constraint\" if constraint else \"requirements\"\n        raise InstallationError(f\"Could not open {kind} file: {exc}\")\n\n    content = _decode_req_file(raw_content, url)\n\n    return url, content\n\n\ndef _decode_req_file(data: bytes, url: str) -> str:\n    for bom, encoding in BOMS:\n        if data.startswith(bom):\n            return data[len(bom) :].decode(encoding)\n\n    for line in data.split(b\"\\n\")[:2]:\n        if line[0:1] == b\"#\":\n            result = PEP263_ENCODING_RE.search(line)\n            if result is not None:\n                encoding = result.groups()[0].decode(\"ascii\")\n                return data.decode(encoding)\n","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/req/req_file.py#L571-L607","documentation":"InstallationError from get_file_content when a requirements (-r) or constraints (-c) file referenced by a bare path cannot be opened. After exhausting URL schemes (http/https/file), pip treats the argument as a filesystem path; any OSError on open(url,'rb') is wrapped with a 'kind' label ('requirements' or 'constraints') so the user knows which file type failed.","triggerScenarios":"'pip install -r missing.txt' (file does not exist), '-c constraints.txt' where constraints.txt is unreadable, or a nested '-r sub/requirements.txt' from inside another requirements file whose path is wrong. Also fires for permission errors and broken symlinks.","commonSituations":"Typo in the requirements filename; running pip from the wrong cwd; CI that did not check out the file; permission/ownership mismatch; relative path that resolves differently in a container.","solutions":["Confirm the file exists and is readable from the cwd pip is running in: 'ls -l <path>'.","Use an absolute path or the correct relative path.","If the error is a permission issue, fix it with chmod/chown.","For nested '-r', remember paths resolve relative to the file containing the '-r' line."],"exampleFix":"# before\npip install -r requirments.txt   # typo\n\n# after\npip install -r requirements.txt","handlingStrategy":"validation","validationCode":"import os\ndef requirement_file_ok(path: str) -> bool:\n    return os.path.isfile(path) and os.access(path, os.R_OK)","typeGuard":"def is_openable_requirements(path: str) -> bool:\n    return requirement_file_ok(path)","tryCatchPattern":"import os\npath = 'requirements.txt'\nif not os.path.isfile(path):\n    print(f'missing {path}'); raise SystemExit(1)\nrun_pip(['install', '-r', path])","preventionTips":["Run pip from the directory containing the requirements file or use absolute paths.","In CI, 'test -f requirements.txt' before pip.","Remember nested '-r' paths resolve relative to the containing file."],"tags":["requirements-file","filesystem","config"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}