{"record":{"id":"8827ea49244d3938","repo":"pypa/pip","slug":"user-base-directory-is-not-specified","errorCode":null,"errorMessage":"User base directory is not specified","messagePattern":"User base directory is not specified","errorType":"exception","errorClass":"UserInstallationInvalid","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/locations/_sysconfig.py","lineNumber":101,"sourceCode":"    if suffixed in _AVAILABLE_SCHEMES:\n        return suffixed\n    if os.name in _AVAILABLE_SCHEMES:  # On Windows, prefx is just called \"nt\".\n        return os.name\n    return \"posix_prefix\"\n\n\ndef _infer_user() -> str:\n    \"\"\"Try to find a user scheme for the current platform.\"\"\"\n    if _PREFERRED_SCHEME_API:\n        return _PREFERRED_SCHEME_API(\"user\")\n    if is_osx_framework() and not running_under_virtualenv():\n        suffixed = \"osx_framework_user\"\n    else:\n        suffixed = f\"{os.name}_user\"\n    if suffixed in _AVAILABLE_SCHEMES:\n        return suffixed\n    if \"posix_user\" not in _AVAILABLE_SCHEMES:  # User scheme unavailable.\n        raise UserInstallationInvalid()\n    return \"posix_user\"\n\n\ndef _infer_home() -> str:\n    \"\"\"Try to find a home for the current platform.\"\"\"\n    if _PREFERRED_SCHEME_API:\n        return _PREFERRED_SCHEME_API(\"home\")\n    suffixed = f\"{os.name}_home\"\n    if suffixed in _AVAILABLE_SCHEMES:\n        return suffixed\n    return \"posix_home\"\n\n\n# Update these keys if the user sets a custom home.\n_HOME_KEYS = [\n    \"installed_base\",\n    \"base\",\n    \"installed_platbase\",","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/locations/_sysconfig.py#L83-L119","documentation":"Raised as UserInstallationInvalid (defined in exceptions.py:276, str returns 'User base directory is not specified') from _infer_user in _sysconfig.py:100-101. It occurs when a --user install is requested but no usable user installation scheme exists: neither the platform-specific user scheme nor the fallback 'posix_user' is present in the available sysconfig schemes, which typically means the user base directory (PYTHONUSERBASE / default user site) is not configured.","triggerScenarios":"Calling get_scheme(..., user=True) (i.e. pip install --user) on an interpreter where sysconfig has no '*_user' scheme and 'posix_user' is not in _AVAILABLE_SCHEMES, so _infer_user falls through to raise UserInstallationInvalid().","commonSituations":"Running --user inside certain embedded/bundled Python distributions that ship a reduced sysconfig; a Python build where ENABLE_USER_SITE is disabled and user site-packages are unavailable; misconfigured PYTHONUSERBASE pointing nowhere.","solutions":["Drop --user and install into a virtualenv (python -m venv) instead.","Set PYTHONUSERBASE to a writable directory and ensure the interpreter supports user-site installs.","Use --target <dir> or --prefix <dir> to install into an explicit location."],"exampleFix":"// before\npip install --user mypkg\n// after\npython -m venv .venv && .venv/bin/pip install mypkg","handlingStrategy":"validation","validationCode":"// Before --user, check a user scheme is available:\nimport sysconfig, site\nif not site.ENABLE_USER_SITE or 'posix_user' not in sysconfig.get_scheme_names():\n    raise SystemExit('user install unsupported here; use a venv or --prefix')","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import UserInstallationInvalid\ntry:\n    scheme = get_scheme(dist, user=True)\nexcept UserInstallationInvalid:\n    # fall back to a venv or --prefix/--target\n    ...","preventionTips":["Prefer virtualenvs over --user for isolated installs.","Check site.ENABLE_USER_SITE before scripting a --user install.","Set PYTHONUSERBASE to a writable dir when --user is required."],"tags":["installation","user-install","scheme","sysconfig"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}