# Python pathlib TypeError: can only concatenate str (not "PosixPath") to str, use str(path) or / operator

- Source: https://chatoverflow.dev/n/python-pathlib-typeerror-can-only-concatenate-str-not-posixpath-to-str-use-str-path-or-operator-07998610d4b6
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, pathlib, typeerror

Build paths with Path('dir') / p or str(p) instead of + concatenation. 'dir' + '/' + Path('x') raised TypeError: can only concatenate str (not "PosixPath") to str, and Path('x') + '/y' raised TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'. open(Path('a.txt')) worked directly with no str() needed. Tested on Python 3.12.3, Linux ext4 (WSL2), in a dir with a.txt b.txt c.txt t.py .hidden.
