Module 'platformdirs' has no attribute 'site_cache_dir'

Hello, I am trying to get my dvc.yaml file set up but am having trouble making the initial stage. For whatever reason I am getting this error. This error persists if I create a new project folder and virtual environment.

$ dvc run

ERROR: unexpected error - module 'platformdirs' has no attribute 'site_cache_dir'

I installed dvc with pip in a virtual environment on a newly created Linux machine running Python 3.10. I’ve listed the packages and their versions below. If anyone knows a resolution to the error, or a workaround, let me know.

aiohttp==3.8.4
aiohttp-retry==2.8.3
aiosignal==1.3.1
amqp==5.1.1
antlr4-python3-runtime==4.9.3
appdirs==1.4.4
async-timeout==4.0.2
asyncssh==2.13.1
atpublic==3.1.1
attrs==22.1.0
billiard==3.6.4.0
build==0.10.0
CacheControl==0.12.11
celery==5.2.7
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
cleo==2.0.1
click==8.1.3
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.2.0
colorama==0.4.6
configobj==5.0.8
crashtest==0.4.1
cryptography==37.0.4
dictdiffer==0.9.0
diskcache==5.6.1
distlib==0.3.6
distro==1.8.0
dpath==2.1.5
dulwich==0.21.3
dvc==2.55.0
dvc-data==0.47.2
dvc-http==2.30.2
dvc-objects==0.21.2
dvc-render==0.3.1
dvc-studio-client==0.8.0
dvc-task==0.2.1
filelock==3.8.0
flatten-dict==0.4.2
flufl.lock==7.1.1
frozenlist==1.3.3
fsspec==2023.4.0
funcy==2.0
gitdb==4.0.10
GitPython==3.1.31
grandalf==0.8
html5lib==1.1
hydra-core==1.3.2
idna==3.4
installer==0.7.0
iterative-telemetry==0.0.8
jaraco.classes==3.2.3
jeepney==0.8.0
joblib==1.2.0
jsonschema==4.16.0
keyring==23.9.3
kombu==5.2.4
lockfile==0.12.2
markdown-it-py==2.2.0
mdurl==0.1.2
more-itertools==8.14.0
msgpack==1.0.4
multidict==6.0.4
nanotime==0.5.2
networkx==3.1
numpy==1.24.3
omegaconf==2.3.0
orjson==3.8.11
packaging==22.0
pandas==2.0.1
pathspec==0.11.1
pexpect==4.8.0
pipenv==2023.3.20
pkginfo==1.9.6
platformdirs==2.5.2
poetry==1.4.2
poetry-core==1.5.2
poetry-plugin-export==1.3.0
prompt-toolkit==3.0.38
psutil==5.9.5
ptyprocess==0.7.0
pycparser==2.21
pydot==1.4.2
pygit2==1.12.0
Pygments==2.15.1
pygtrie==2.5.0
pyparsing==3.0.9
pyproject_hooks==1.0.0
pyrsistent==0.18.1
python-dateutil==2.8.2
pytz==2023.3
PyYAML==6.0
rapidfuzz==2.13.7
requests==2.28.1
requests-toolbelt==0.9.1
rich==13.3.5
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.7
scikit-learn==1.2.2
scipy==1.10.1
scmrepo==1.0.2
SecretStorage==3.3.3
shellingham==1.5.0
shortuuid==1.0.11
shtab==1.6.1
six==1.16.0
smmap==5.0.0
sqltrie==0.3.1
tabulate==0.9.0
threadpoolctl==3.1.0
tomli==2.0.1
tomlkit==0.11.5
tqdm==4.65.0
trove-classifiers==2022.12.22
typing_extensions==4.5.0
tzdata==2023.3
urllib3==1.26.12
vine==5.0.0
virtualenv==20.21.0
virtualenv-clone==0.5.7
voluptuous==0.13.1
wcwidth==0.2.6
webencodings==0.5.1
yarl==1.9.2
zc.lockfile==3.0.post1

Hi. DVC requires platformdirs>=3.1.1. There may be something that’s making pip install older version.
Please try updating platformdirs with:

python -m pip install "platformdirs>=3.1.1"
1 Like

I have platformdirs version 3.2.0 and I am still getting this error with dvc pull.

$ dvc pull
ERROR: unexpected error - module 'platformdirs' has no attribute 'site_cache_dir'

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!

$ pip list | grep platformdirs
platformdirs           3.2.0

When I switch to platformdirs verion 3.1.1. it solves the issue.

Could you show dvc doctor, please? My guess is that pip list is showing a different environment than the one dvc is installed in. Just want to make sure.

$ dvc doctor
DVC version: 2.54.0 (pip)

Platform: Python 3.8.16 on Windows-10-10.0.19045-SP0
Subprojects:
dvc_data = 0.47.1
dvc_objects = 0.21.1
dvc_render = 0.3.1
dvc_task = 0.2.0
scmrepo = 1.0.1
Supports:
http (aiohttp = 3.8.4, aiohttp-retry = 2.8.3),
https (aiohttp = 3.8.4, aiohttp-retry = 2.8.3)
Cache types:
Cache directory: NTFS on M:
Caches: local
Remotes: local
Workspace directory: NTFS on M:
Repo: dvc, git
Repo.site_cache_dir: C:\ProgramData\iterative\dvc\Cache\repo\120a5116ac3914e12e2015892f40c3e5