{"id":"222d5e5794c03a47","repo":"pypa/pip","slug":"build-constraint-cannot-be-used-with-no-build","errorCode":null,"errorMessage":"--build-constraint cannot be used with --no-build-isolation.","messagePattern":"--build-constraint cannot be used with --no-build-isolation\\.","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/cli/cmdoptions.py","lineNumber":158,"sourceCode":"        from pip._internal.utils import pylock as pylock_utils\n\n        for filename in options.requirements:\n            if pylock_utils.is_valid_pylock_filename(filename):\n                raise CommandError(\n                    \"Platform and interpreter constraints using \"\n                    \"--python-version, --platform, --abi, or --implementation, \"\n                    f\"are not supported when selecting requirements from {filename!r}\"\n                )\n\n\ndef check_build_constraints(options: Values) -> None:\n    \"\"\"Function for validating build constraints options.\n\n    :param options: The OptionParser options.\n    \"\"\"\n    if hasattr(options, \"build_constraints\") and options.build_constraints:\n        if not options.build_isolation:\n            raise CommandError(\n                \"--build-constraint cannot be used with --no-build-isolation.\"\n            )\n\n        # Import here to avoid circular imports\n        from pip._internal.network.session import PipSession\n        from pip._internal.req.req_file import get_file_content\n\n        # Eagerly check build constraints file contents\n        # is valid so that we don't fail in when trying\n        # to check constraints in isolated build process\n        with PipSession() as session:\n            for constraint_file in options.build_constraints:\n                get_file_content(constraint_file, session)\n\n\ndef _path_option_check(option: Option, opt: str, value: str) -> str:\n    return os.path.expanduser(value)\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/cli/cmdoptions.py#L140-L176","documentation":"Raised by check_build_constraints() in cmdoptions.py:158 when --build-constraint is specified together with --no-build-isolation. Build constraints are designed to control dependencies in the isolated build environment; without build isolation, there is no separate environment to constrain, making the option meaningless and potentially confusing.","triggerScenarios":"Calling `pip install --build-constraint constraints.txt --no-build-isolation <pkg>`. The check at cmdoptions.py:156-160 verifies that if build_constraints are set, build_isolation must be True (the default).","commonSituations":"Trying to pin build dependency versions while also disabling isolation (e.g., to use pre-installed build tools). Not understanding that build constraints only apply within isolated environments. Copy-pasting flags from different pip invocations.","solutions":["Remove --no-build-isolation to keep build isolation enabled (allows --build-constraint to work).","Remove --build-constraint if you intentionally disabled build isolation and manage build deps manually.","Pre-install the exact build dependency versions you need in your environment and drop both flags."],"exampleFix":"# before\npip install --build-constraint build-constraints.txt --no-build-isolation mypkg\n\n# after (choose one):\n# Option A: keep build constraints, enable isolation\npip install --build-constraint build-constraints.txt mypkg\n# Option B: keep no isolation, drop build constraints\npip install --no-build-isolation mypkg","handlingStrategy":"validation","validationCode":"def validate_build_constraint_options(options):\n    \"\"\"Ensure --build-constraint is not used with --no-build-isolation.\"\"\"\n    if options.get('build_constraints') and not options.get('build_isolation', True):\n        return False\n    return True","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import CommandError\ntry:\n    # pip install with build-constraint + no-build-isolation\nexcept CommandError as e:\n    if '--build-constraint' in str(e):\n        # either remove --no-build-isolation or remove --build-constraint\n","preventionTips":["Understand that build constraints require an isolated build environment.","If disabling isolation, pre-install build deps manually instead.","Document your build-isolation strategy in project README."],"tags":["cli","build-isolation","build-constraint","option-conflict","validation"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}