{"record":{"id":"4c77f3dc2a0b5ab6","repo":"pypa/pip","slug":"can-not-perform-a-user-install-user-site-pack-4c77f3","errorCode":null,"errorMessage":"Can not perform a '--user' install. User site-packages are disabled for this Python.","messagePattern":"Can not perform a '--user' install\\. User site-packages are disabled for this Python\\.","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/commands/install.py","lineNumber":806,"sourceCode":"        logger.debug(\"Non-user install by explicit request\")\n        return False\n\n    # If we have been asked for a user install explicitly, check compatibility.\n    if use_user_site:\n        if prefix_path:\n            raise CommandError(\n                \"Can not combine '--user' and '--prefix' as they imply \"\n                \"different installation locations\"\n            )\n        if virtualenv_no_global():\n            raise InstallationError(\n                \"Can not perform a '--user' install. User site-packages \"\n                \"are not visible in this virtualenv.\"\n            )\n        # Catch all remaining cases which honour the site.ENABLE_USER_SITE\n        # value, such as a plain Python installation (e.g. no virtualenv).\n        if not site.ENABLE_USER_SITE:\n            raise InstallationError(\n                \"Can not perform a '--user' install. User site-packages \"\n                \"are disabled for this Python.\"\n            )\n        logger.debug(\"User install by explicit request\")\n        return True\n\n    # If we are here, user installs have not been explicitly requested/avoided\n    assert use_user_site is None\n\n    # user install incompatible with --prefix/--target\n    if prefix_path or target_dir:\n        logger.debug(\"Non-user install due to --prefix or --target option\")\n        return False\n\n    # If user installs are not enabled, choose a non-user install\n    if not site.ENABLE_USER_SITE:\n        logger.debug(\"Non-user install because user site-packages disabled\")\n        return False","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/commands/install.py#L788-L824","documentation":"Raised by pip's decide_user_install() when the user explicitly passes --user but Python's site.ENABLE_USER_SITE flag is False, meaning the per-user site-packages directory is disabled for this interpreter. This is distinct from the virtualenv case (which is caught one branch earlier); it fires for a plain Python whose site customization, -s flag, or PYTHONNOUSERSITE environment variable has turned user installs off. The install is aborted because pip cannot honor --user when the interpreter refuses to use the user site directory.","triggerScenarios":"Running `pip install --user <pkg>` when PYTHONNOUSERSITE is set to a truthy value, or the Python process was started with the `-s` (no user site) interpreter flag, or a custom sitecustomize.py sets ENABLE_USER_SITE=False. Also triggered by tools that hardcode `--user` (e.g. certain tox/Jupyter configs) inside containers or system Pythons that ship with user site disabled.","commonSituations":"System-packaged Python on Linux distributions that disable user site by default; CI containers where PYTHONNOUSERSITE is exported; running python -s -m pip install --user; Jupyter %pip magic in an environment where the kernel was launched with -s.","solutions":["Drop the --user flag and install into a virtualenv instead: `python -m venv .venv && .venv/bin/pip install <pkg>`.","Unset PYTHONNOUSERSITE (`unset PYTHONNOUSERSITE`) and ensure the interpreter is not started with -s, then retry --user.","Install into the system site-packages with appropriate permissions (e.g. `sudo pip install` or, better, use a venv) if --user is not required.","If a wrapper tool forces --user, configure it to use --prefix or a target directory instead."],"exampleFix":"# before\nPYTHONNOUSERSITE=1 pip install --user requests\n# after\nunset PYTHONNOUSERSITE\npip install --user requests\n# or, preferred:\npython -m venv .venv && .venv/bin/pip install requests","handlingStrategy":"validation","validationCode":"import site, sys\n\n# Run before invoking pip with --user\nif not site.ENABLE_USER_SITE or sys.flags.no_user_site:\n    raise SystemExit('User site-packages disabled; use a venv instead of --user')\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer virtualenvs over --user installs entirely.","Check site.ENABLE_USER_SITE before scripting a --user install.","Do not export PYTHONNOUSERSITE in dotfiles unless intentional."],"tags":["pip","install","user-site","configuration","environment"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}