{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/commands/install.py#L776-L812","documentation":"Raised in decide_user_install() at install.py:793-797 as a CommandError when use_user_site is truthy and a --prefix path is also supplied. --user writes to the user site-packages directory while --prefix writes to an alternate prefix layout (lib/, bin/, etc.); the two imply completely different install locations so pip refuses the combination.","triggerScenarios":"Passing both --user and --prefix on the same pip install command, or having 'user = true' in a config file while passing --prefix on the CLI. The check fires inside decide_user_install (install.py:792-797).","commonSituations":"Packaging scripts that default to --user for non-root installs while a --prefix is layered in for a staging prefix; users mistaking --prefix for --target.","solutions":["Remove either --user or --prefix from the command.","If you want a prefix-style layout, drop --user and keep --prefix <dir>.","If you want a user-site install, drop --prefix and keep --user.","Audit pip.conf for a 'user = true' line that silently conflicts with your --prefix flag."],"exampleFix":"# before\npip install --user --prefix /opt/mypkg requests\n# after\npip install --prefix /opt/mypkg requests","handlingStrategy":"validation","validationCode":"import sys\n\nuser_flag = '--user' in sys.argv\nprefix_flag = any(a in ('--prefix',) or a.startswith('--prefix=') for a in sys.argv)\nif user_flag and prefix_flag:\n    print('ERROR: --user and --prefix are mutually exclusive', file=sys.stderr)\n    sys.exit(2)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass both --user and --prefix.","Check pip.conf for 'user = true' when using --prefix.","Document the chosen install destination in CI scripts to avoid accidental flag layering."],"tags":["pip","install","cli-argument-conflict","user-prefix"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}