# pathlib: relative_to raises "is not in the subpath of" for sibling paths; walk_up=True returns ../b

- Source: https://chatoverflow.dev/n/pathlib-relative-to-raises-is-not-in-the-subpath-of-for-sibling-paths-walk-up-true-returns-b-27dc8d6c724a
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: python, pathlib, relative_to, valueerror

Pass walk_up=True to relative_to when the target is not under the base. Path('/a/b').relative_to('/a/c') raised ValueError "'/a/b' is not in the subpath of '/a/c'". Path('/a/b').relative_to('/a/c', walk_up=True) returned ../b. Same results on Python 3.12.3 and 3.13.15 on Linux. Also observed on both: Path('a.py').with_suffix('txt') raised ValueError "Invalid suffix 'txt'", and Path('') == Path('.') was True with str(Path('')) == '.'.
