Installation
This page lists what platformdirs needs, how to install it, how to check that it works, and what to do when the installation or the first import misbehaves.
Requirements
| Requirement | Value |
|---|---|
| Python | 3.11 or newer (requires-python = ">=3.11") |
| Tested interpreters | CPython 3.11, 3.12, 3.13, 3.14, 3.15 (including the free-threaded 3.15t build) and PyPy 3.11 |
| Runtime dependencies | None. platformdirs uses only the standard library. |
| Operating systems | Any. Linux and other Unix systems, macOS, Windows, Android and iOS have dedicated backends. |
| License | MIT |
On Windows, platformdirs uses ctypes to call the Known Folder API. If ctypes is unavailable it falls back to the registry (winreg), and if that is also unavailable, to environment variables. No extra package is needed in any case.
On Android, platformdirs can optionally use pyjnius (when your app already ships it, as python-for-android apps do) to ask the Android runtime for exact folders. It works without pyjnius by inspecting sys.path. See Android.
Note: platformdirs 4.x requires Python 3.11+. If you must support an older interpreter, pin an older release from the changelog that still supports it.
Install from PyPI
The package is published on PyPI as platformdirs:
pip install platformdirs
Any PyPI-compatible tool works the same way, for example adding platformdirs to the dependencies list in your pyproject.toml:
[project]
dependencies = [
"platformdirs>=4.14",
]
What Gets Installed
| Module | Purpose |
|---|---|
platformdirs |
The public API: PlatformDirs, AppDirs, the module-level functions, RuntimeDirWarning, __version__, __version_info__. |
platformdirs.api |
The abstract base class PlatformDirsABC. |
platformdirs.unix, .macos, .windows, .android, .ios |
One backend class per platform (Unix, MacOS, Windows, Android, IOS). |
platformdirs.testing |
The isolated_dirs() context manager for tests. |
platformdirs.pytest_plugin |
The platformdirs_isolated pytest fixture, registered through the pytest11 entry point. |
platformdirs.__main__ |
The python -m platformdirs diagnostic report. |
The package ships a py.typed marker, so type checkers use its inline annotations.
The pytest Plugin
Installing platformdirs also registers a pytest plugin. It only defines the platformdirs_isolated fixture and does nothing unless a test requests that fixture; it imports platformdirs.testing lazily. If you need to disable it, use pytest's standard switch:
pytest -p no:platformdirs
See Testing Helpers.
Verify the Installation
Check the version:
python -c "import platformdirs; print(platformdirs.__version__)"
4.14.9
platformdirs.__version_info__ holds the same version as a tuple, for example (4, 14, 9).
Then print every directory for the current machine with the built-in report:
python -m platformdirs
On Windows, the first section of the output looks like this (captured on a real machine, user name replaced):
-- platformdirs 4.14.9 --
-- app dirs (with optional 'version')
user_data_dir: C:\Users\<User>\AppData\Local\MyCompany\MyApp\1.0
user_config_dir: C:\Users\<User>\AppData\Local\MyCompany\MyApp\1.0
user_cache_dir: C:\Users\<User>\AppData\Local\MyCompany\MyApp\Cache\1.0
user_state_dir: C:\Users\<User>\AppData\Local\MyCompany\MyApp\1.0
user_log_dir: C:\Users\<User>\AppData\Local\MyCompany\MyApp\1.0\Logs
user_documents_dir: C:\Users\<User>\Documents
...
The full format is described in Command Line Report.
Troubleshooting Installation
ERROR: Package 'platformdirs' requires a different Python
Your interpreter is older than 3.11. Upgrade Python, or pin an older platformdirs release that supported your interpreter.
Another Tool Already Installed a Different Version
platformdirs is a dependency of many popular tools, so an environment often already contains it. Check which copy is imported:
python -c "import platformdirs; print(platformdirs.__version__, platformdirs.__file__)"
If the version is older than you expect, upgrade it in that environment with pip install --upgrade platformdirs, or use a virtual environment for your project.
ModuleNotFoundError: No module named 'platformdirs.version' From a Source Checkout
The platformdirs/version.py module is generated at build time by hatch-vcs from the git history. It does not exist in a plain clone, so putting src/ on sys.path fails at import platformdirs. Install the checkout instead (pip install -e ., or tox r -e dev, which creates an editable development environment). See Contributing.
python -m platformdirs Prints an Error Instead of a Path
That is the report doing its job: it catches RuntimeError and PermissionError for each property and prints the message, for example when HOME is not set. See Troubleshooting.