{"id":"62a7d71f9ad66465","repo":"pypa/pip","slug":"file-r-does-not-exist","errorCode":null,"errorMessage":"file '%r' does not exist","messagePattern":"file '%r' does not exist","errorType":"exception","errorClass":"DistlibException","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/distlib/util.py","lineNumber":515,"sourceCode":"\n    def record_as_written(self, path):\n        if self.record:\n            self.files_written.add(path)\n\n    def newer(self, source, target):\n        \"\"\"Tell if the target is newer than the source.\n\n        Returns true if 'source' exists and is more recently modified than\n        'target', or if 'source' exists and 'target' doesn't.\n\n        Returns false if both exist and 'target' is the same age or younger\n        than 'source'. Raise PackagingFileError if 'source' does not exist.\n\n        Note that this test is not very accurate: files created in the same\n        second will have the same \"age\".\n        \"\"\"\n        if not os.path.exists(source):\n            raise DistlibException(\"file '%r' does not exist\" % os.path.abspath(source))\n        if not os.path.exists(target):\n            return True\n\n        return os.stat(source).st_mtime > os.stat(target).st_mtime\n\n    def copy_file(self, infile, outfile, check=True):\n        \"\"\"Copy a file respecting dry-run and force flags.\n        \"\"\"\n        self.ensure_dir(os.path.dirname(outfile))\n        logger.info('Copying %s to %s', infile, outfile)\n        if not self.dry_run:\n            msg = None\n            if check:\n                if os.path.islink(outfile):\n                    msg = '%s is a symlink' % outfile\n                elif os.path.exists(outfile) and not os.path.isfile(outfile):\n                    msg = '%s is a non-regular file' % outfile\n            if msg:","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/distlib/util.py#L497-L533","documentation":"Raised by FileOperator.newer() when the source file given to it does not exist (os.path.exists(source) is False). newer() compares modification times to decide whether a target needs updating, so a missing source is a fatal condition and DistlibException (with the absolute path) is raised. The error message uses '%r' formatting on the abspath.","triggerScenarios":"Calling operator.newer(missing_source, target) where missing_source does not exist on disk; passing a stale or typo'd source path to copy/install operations that internally call newer().","commonSituations":"Build/install steps referencing files that were moved/deleted, race conditions where a file is removed between listing and copying, or wrong working directory when computing relative source paths.","solutions":["Verify the source path exists with os.path.exists() before calling newer().","Check the absolute path in the error message against your project layout and correct the path.","Ensure the file-generation step that produces the source runs before newer() is called."],"exampleFix":"// before\noperator.newer('build/missing.bin', target)\n// after\nimport os\nif os.path.exists('build/missing.bin'):\n    operator.newer('build/missing.bin', target)\nelse:\n    raise FileNotFoundError('build/missing.bin')","handlingStrategy":"validation","validationCode":"import os\ndef safe_newer(operator, source, target):\n    if not os.path.exists(source):\n        raise FileNotFoundError(source)\n    return operator.newer(source, target)","typeGuard":null,"tryCatchPattern":"from distlib.util import DistlibException\ntry:\n    need_update = operator.newer(source, target)\nexcept DistlibException as e:\n    if 'does not exist' in str(e):\n        regenerate_source(source)\n        need_update = True\n    else:\n        raise","preventionTips":["Check os.path.exists(source) before calling newer().","Ensure source-generation steps complete before install/copy steps.","Log the absolute path from the error to quickly locate the missing file."],"tags":["filesystem","file-existence","packaging","build"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}