{"record":{"id":"71fd3b45a2b5e81a","repo":"pypa/pip","slug":"cannot-set-user-and-prefix-together","errorCode":null,"errorMessage":"Cannot set --user and --prefix together","messagePattern":"Cannot set --user and --prefix together","errorType":"exception","errorClass":"InvalidSchemeCombination","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/locations/_sysconfig.py","lineNumber":150,"sourceCode":"    root: str | None = None,\n    isolated: bool = False,\n    prefix: str | None = None,\n) -> Scheme:\n    \"\"\"\n    Get the \"scheme\" corresponding to the input parameters.\n\n    :param dist_name: the name of the package to retrieve the scheme for, used\n        in the headers scheme path\n    :param user: indicates to use the \"user\" scheme\n    :param home: indicates to use the \"home\" scheme\n    :param root: root under which other directories are re-based\n    :param isolated: ignored, but kept for distutils compatibility (where\n        this controls whether the user-site pydistutils.cfg is honored)\n    :param prefix: indicates to use the \"prefix\" scheme and provides the\n        base directory for the same\n    \"\"\"\n    if user and prefix:\n        raise InvalidSchemeCombination(\"--user\", \"--prefix\")\n    if home and prefix:\n        raise InvalidSchemeCombination(\"--home\", \"--prefix\")\n\n    if home is not None:\n        scheme_name = _infer_home()\n    elif user:\n        scheme_name = _infer_user()\n    else:\n        scheme_name = _infer_prefix()\n\n    # Special case: When installing into a custom prefix, use posix_prefix\n    # instead of osx_framework_library. See _should_use_osx_framework_prefix()\n    # docstring for details.\n    if prefix is not None and scheme_name == \"osx_framework_library\":\n        scheme_name = \"posix_prefix\"\n\n    if home is not None:\n        variables = {k: home for k in _HOME_KEYS}","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/locations/_sysconfig.py#L132-L168","documentation":"Raised as InvalidSchemeCombination('--user','--prefix') (exceptions.py:283, str yields 'Cannot set --user and --prefix together') from get_scheme in _sysconfig.py:149-150. The two install schemes are mutually exclusive: --user installs into the per-user site, while --prefix installs into an arbitrary prefix, so passing both is ambiguous and rejected before any path is computed.","triggerScenarios":"Invoking get_scheme(dist_name, user=True, prefix=<non-None>) — i.e. combining `pip install --user --prefix /some/path`.","commonSituations":"Copy-pasting flags from two different install recipes; a wrapper script or CI matrix that always passes --user but also injects --prefix; misconfigured build tooling that forwards both.","solutions":["Pick one target: use --user for per-user installs, or --prefix for a custom prefix location.","If installing into a virtualenv-style layout, prefer creating a venv and dropping both flags.","Audit wrapper scripts/CI for flags that conflict before forwarding them to pip."],"exampleFix":"// before\npip install --user --prefix /opt/mypkg mypkg\n// after (choose one)\npip install --prefix /opt/mypkg mypkg","handlingStrategy":"validation","validationCode":"// Reject conflicting flags before calling get_scheme / pip:\nif user and prefix:\n    raise SystemExit('--user and --prefix are mutually exclusive')","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import InvalidSchemeCombination\ntry:\n    scheme = get_scheme(dist, user=user, prefix=prefix)\nexcept InvalidSchemeCombination:\n    # drop one of the conflicting flags\n    ...","preventionTips":["Never combine --user with --prefix.","Validate install-target flags in wrapper scripts before forwarding to pip.","Document a single canonical install-location strategy in CI templates."],"tags":["installation","scheme","argument-conflict","sysconfig"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}