Adding a directory to sys.path with pathlib
you need to append the path as a string to sys.path
:
PROJECT_DIR = Path(__file__).parents[2]
sys.path.append(
str(PROJECT_DIR / 'apps')
)
PROJECT_DIR
is instance of PosixPath
which has all the goodies like /
and parents
etc. but you need to convert it to a regular string if you want to use is somewhere a string is expected - like sys.path
.
Support for path-like-objects on sys.path
is coming (see this pull request) but not here yet.