{"record":{"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/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/cli/cmdoptions.py#L140-L176","documentation":"Raised as CommandError by check_build_constraints (cmdoptions.py:158) when --build-constraint is used together with --no-build-isolation. Build constraints are injected into the ISOLATED build environment to constrain which versions of build dependencies (setuptools, wheel, etc.) the PEP 517 backend may use. Disabling build isolation means there is no separate environment to apply those constraints to, so the two options are incompatible by design (lines 156-160).","triggerScenarios":"`pip install --build-constraint constraints.txt --no-build-isolation <pkg>` where constraints.txt pins build-time dependency versions.","commonSituations":"Hardening builds in an air-gapped/offline setup where the user also disables isolation to reuse a pre-populated environment; copy-pasting a hardened-build command and adding --no-build-isolation to speed up builds.","solutions":["Keep build isolation enabled (remove --no-build-isolation) so --build-constraint takes effect in the isolated venv.","If you must disable isolation, drop --build-constraint and instead pin the build tools yourself in the active environment."],"exampleFix":"# before\npip install --build-constraint build-constraints.txt --no-build-isolation <pkg>\n# after\npip install --build-constraint build-constraints.txt <pkg>","handlingStrategy":"validation","validationCode":"# Reject the combination before building the command line.\ndef validate_build_constraint(opts):\n    if opts.get(\"build_constraints\") and not opts.get(\"build_isolation\"):\n        raise ValueError(\"--build-constraint requires build isolation; remove --no-build-isolation\")\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep build isolation on whenever you use --build-constraint.","Pin build tools in the active environment only when you intentionally disable isolation."],"tags":["cli-options","build-constraint","build-isolation","command-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}