{"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":"validation","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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/locations/_sysconfig.py#L132-L168","documentation":"InvalidSchemeCombination raised by get_scheme() when both user=True and prefix=<set> are passed. The two installation schemes are mutually exclusive - --user installs into the per-user site, --prefix into an arbitrary prefix - so combining them is ambiguous and rejected up front.","triggerScenarios":"Calling get_scheme(dist_name, user=True, prefix='/some/path') or running pip with both --user and --prefix on the command line / in config. The check at line 149-150 fires before any scheme selection.","commonSituations":"A pip.conf that sets both 'user = true' and a 'prefix = ...'; passing --user --prefix together on the CLI; an environment variable (PIP_USER=1) combined with a --prefix flag; a wrapper script that always adds --user.","solutions":["Decide one target: use --user OR --prefix, not both.","Check pip.conf / pip.ini and PIP_* env vars for stale 'user'/'prefix' settings and remove one.","If you need a custom install location, use --prefix alone; if you want per-user install, drop --prefix.","Run 'pip config list' to see where the conflicting options come from."],"exampleFix":"# before\npip install --user --prefix /opt/py somepkg\n\n# after (pick one)\npip install --user somepkg\n# or\npip install --prefix /opt/py somepkg","handlingStrategy":"validation","validationCode":"def scheme_args_ok(user: bool, prefix) -> bool:\n    return not (user and prefix)\n# at CLI parse time:\nassert scheme_args_ok(args.user, args.prefix), 'cannot combine --user and --prefix'","typeGuard":"def valid_scheme_combo(user: bool, home, prefix) -> bool:\n    return not (user and prefix) and not (home and prefix)","tryCatchPattern":"from pip._internal.exceptions import InvalidSchemeCombination\ntry:\n    get_scheme(name, user=u, home=h, prefix=p)\nexcept InvalidSchemeCombination as e:\n    # prompt user to pick one scheme\n    ...","preventionTips":["Pass only one of --user/--home/--prefix.","Audit pip.conf and PIP_* env vars for inherited options.","Run 'pip config list' before scripted installs.","Document the intended install target in CI scripts."],"tags":["install-location","scheme","cli","mutually-exclusive"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}