{"record":{"id":"c749583ea2094256","repo":"pypa/pip","slug":"path-s-cannot-be-absolute","errorCode":null,"errorMessage":"path '%s' cannot be absolute","messagePattern":"path '(.+?)' cannot be absolute","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/distlib/util.py","lineNumber":474,"sourceCode":"        return value\n\n\ndef convert_path(pathname):\n    \"\"\"Return 'pathname' as a name that will work on the native filesystem.\n\n    The path is split on '/' and put back together again using the current\n    directory separator.  Needed because filenames in the setup script are\n    always supplied in Unix style, and have to be converted to the local\n    convention before we can actually use them in the filesystem.  Raises\n    ValueError on non-Unix-ish systems if 'pathname' either starts or\n    ends with a slash.\n    \"\"\"\n    if os.sep == '/':\n        return pathname\n    if not pathname:\n        return pathname\n    if pathname[0] == '/':\n        raise ValueError(\"path '%s' cannot be absolute\" % pathname)\n    if pathname[-1] == '/':\n        raise ValueError(\"path '%s' cannot end with '/'\" % pathname)\n\n    paths = pathname.split('/')\n    while os.curdir in paths:\n        paths.remove(os.curdir)\n    if not paths:\n        return os.curdir\n    return os.path.join(*paths)\n\n\nclass FileOperator(object):\n\n    def __init__(self, dry_run=False):\n        self.dry_run = dry_run\n        self.ensured = set()\n        self._init_record()\n","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/distlib/util.py#L456-L492","documentation":"Raised as ValueError by distlib.util.convert_path when, on a non-Unix system (os.sep != '/', i.e. Windows), the supplied pathname starts with '/'. convert_path translates Unix-style '/' separators in setup-script filenames to the native separator; an absolute leading slash is rejected because setup filenames are expected to be relative. On POSIX (os.sep == '/') the function is a no-op and never raises.","triggerScenarios":"Calling convert_path('/abs/path/to/file') on Windows; setup.py data_files or package_data entries containing absolute Unix paths; cross-platform packaging code that passes platform-absolute paths to convert_path on Windows.","commonSituations":"Building wheels/sdists on Windows where a resource path was constructed with a leading '/'; config files supplying absolute paths into a packaging pipeline that calls convert_path.","solutions":["Pass relative paths only; strip any leading '/' (and drive letters) before calling convert_path.","Guard with: if os.name != 'nt' or not pathname.startswith('/'): before converting.","Build resource paths with os.path.join of relative components instead of hard-coding slashes."],"exampleFix":"# before\nconvert_path('/data/templates/index.html')\n# after\nconvert_path('data/templates/index.html')","handlingStrategy":"validation","validationCode":"def safe_convert_path(pathname):\n    if os.sep != '/' and pathname.startswith('/'):\n        pathname = pathname.lstrip('/')\n    return convert_path(pathname)","typeGuard":"def is_relative_unix_path(s: str) -> bool:\n    return isinstance(s, str) and not s.startswith('/')","tryCatchPattern":"try:\n    convert_path(pathname)\nexcept ValueError as e:\n    if 'cannot be absolute' in str(e):\n        convert_path(pathname.lstrip('/'))","preventionTips":["Only pass relative paths to convert_path.","Build paths with os.path.join of relative components."],"tags":["filesystem","paths","windows","distlib","packaging"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}