{"record":{"id":"d22e80df0861cd40","repo":"pypa/pip","slug":"can-not-combine-user-and-prefix-as-they-im","errorCode":null,"errorMessage":"Can not combine '--user' and '--prefix' as they imply different installation locations","messagePattern":"Can not combine '--user' and '--prefix' as they imply different installation locations","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/commands/install.py","lineNumber":794,"sourceCode":") -> bool:\n    \"\"\"Determine whether to do a user install based on the input options.\n\n    If use_user_site is False, no additional checks are done.\n    If use_user_site is True, it is checked for compatibility with other\n    options.\n    If use_user_site is None, the default behaviour depends on the environment,\n    which is provided by the other arguments.\n    \"\"\"\n    # In some cases (config from tox), use_user_site can be set to an integer\n    # rather than a bool, which 'use_user_site is False' wouldn't catch.\n    if (use_user_site is not None) and (not use_user_site):\n        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","sourceCodeStart":776,"sourceCodeEnd":812,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/commands/install.py#L776-L812","documentation":"Raised by `pip install` when both --user and --prefix are supplied. decide_user_install at install.py:793 raises CommandError because --user installs to the user site-packages (~/.local) while --prefix installs to an arbitrary prefix's lib — the two locations conflict and cannot be honored together.","triggerScenarios":"Invoking `pip install --user --prefix /opt/mypython <pkg>` — use_user_site is truthy and prefix_path is set, hitting install.py:793-797. Note this check is only reached when --user is explicitly requested (truthy).","commonSituations":"User combines flags assuming pip will prefer one, or migrates between user installs and prefix installs without removing the old flag.","solutions":["Choose one: drop --user (use --prefix alone) or drop --prefix (use --user alone).","For a relocatable install under a prefix use `pip install --prefix /opt/mypython <pkg>`.","For per-user install use `pip install --user <pkg>`."],"exampleFix":"// before\npip install --user --prefix /opt/mypython numpy\n// after\npip install --prefix /opt/mypython numpy","handlingStrategy":"validation","validationCode":"# Reject combining --user and --prefix before invoking pip install\ndef install_opts_ok(use_user, prefix_path):\n    if use_user and prefix_path is not None:\n        raise ValueError(\"--user and --prefix are mutually exclusive\")\n    return True\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass both --user and --prefix in the same invocation.","Decide between user-site and prefix-based installs up front."],"tags":["cli","pip-install","argument-validation","mutually-exclusive-flags","usage-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}