[Fixed]-Running collectstatic on server : AttributeError: 'PosixPath' object has no attribute 'startswith'


You’re using Python 3.5. Support for Path objects in the os module was added in Python 3.6. You can:

  • either upgrade to Python 3.6; or

  • avoid using Path objects:

    BASE_DIR = os.path.abspath(os.path.join(__file__, '../../../'))
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')


This was my earlier settings . I am using Python 3.5. Django 2.1.

BASE_DIR = Path(__file__).resolve().parent.parent.parent

I changed just one thing:

STATIC_ROOT = str(BASE_DIR / 'static')

It worked fine.


In my case it was because i installed in manually (which was the old version). the new python versions (>=3.6) have the pathlib library included.

So I simply did pip uninstall pathlib so that it could use the one that comes already bundled with python. When i ran the code again it worked fine.


I got the error from some Databricks internal library. I had imported Pathlib because I needed to get the current working directory.

When I removed

    from pathlib import Path

and used


to get the current directory it started working. Looks like Pathlib changed sys.path to return a list of PosixPath objects instead of a list of strings.

Leave a comment