{"record":{"id":"cde3959d43ce8c2d","repo":"pypa/pip","slug":"script-script-r-requires-a-different-python-py","errorCode":null,"errorMessage":"Script {script!r} requires a different Python: {py_version} not in {script_requires_python!r}","messagePattern":"Script (.+?) requires a different Python: (.+?) not in (.+?)","errorType":"exception","errorClass":"UnsupportedPythonVersion","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/cli/req_command.py","lineNumber":417,"sourceCode":"            if len(options.requirements_from_scripts) > 1:\n                raise CommandError(\"--requirements-from-script can only be given once\")\n\n            script = options.requirements_from_scripts[0]\n            try:\n                script_metadata = pep723_metadata(script)\n            except PEP723Exception as exc:\n                raise CommandError(exc.msg)\n\n            script_requires_python = script_metadata.get(\"requires-python\", \"\")\n\n            if script_requires_python and not options.ignore_requires_python:\n                target_python = make_target_python(options)\n\n                if not check_requires_python(\n                    requires_python=script_requires_python,\n                    version_info=target_python.py_version_info,\n                ):\n                    raise UnsupportedPythonVersion(\n                        f\"Script {script!r} requires a different Python: \"\n                        f\"{target_python.py_version} not in {script_requires_python!r}\"\n                    )\n\n            for req in script_metadata.get(\"dependencies\", []):\n                req_to_add = install_req_from_req_string(\n                    req,\n                    isolated=options.isolated_mode,\n                    user_supplied=True,\n                )\n                requirements.append(req_to_add)\n\n        if options.require_hashes and options.no_require_hashes:\n            raise CommandError(\n                \"--require-hashes and --no-require-hashes are mutually exclusive\"\n            )\n\n        # If any requirement has hash options, enable hash checking for all","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/cli/req_command.py#L399-L435","documentation":"Raised as UnsupportedPythonVersion from RequirementCommand.get_requirements (req_command.py:417) when a PEP 723 script's requires-python metadata does not permit the target Python version. Pip parses the script's inline metadata via pep723_metadata (line 404), reads requires-python (line 408), and unless --ignore-requires-python is set, calls check_requires_python (line 413) against the target python (derived from options via make_target_python). A mismatch aborts the install with this message naming the script, the active version, and the required specifier.","triggerScenarios":"`pip install --requirements-from-script tool.py` where tool.py's PEP 723 block says `# /// requires-python = >=3.11` but the active interpreter is 3.10.","commonSituations":"Running a tool script under an older interpreter than the script author intended; CI matrix mismatch between the runner's Python and the script's requires-python; inheriting a script that pins a newer Python.","solutions":["Run pip under an interpreter that satisfies the script's requires-python (use `pip --python <newer-interpreter> install --requirements-from-script tool.py`).","If the constraint is wrong, edit the script's PEP 723 requires-python field to match the actual requirement.","Bypass the check with `--ignore-requires-python` only if you understand the script may break on this Python."],"exampleFix":"# before (active interpreter is 3.10)\npip install --requirements-from-script tool.py\n# after\npip --python /usr/bin/python3.12 install --requirements-from-script tool.py","handlingStrategy":"validation","validationCode":"# Check the script's requires-python against the target interpreter before installing.\nfrom pip._internal.utils.compatibility_tags import check_requires_python\nfrom pip._internal.req.req_file import pep723_metadata  # or equivalent parser\nimport sys\ndef script_python_ok(script):\n    meta = pep723_metadata(script)\n    rp = meta.get(\"requires-python\", \"\")\n    if rp and not check_requires_python(rp, sys.version_info):\n        raise SystemExit(f\"{script} requires {rp}; active is {sys.version_info[:2]}\")\n    return True","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run tools under the interpreter their PEP 723 requires-python specifies.","Keep CI Python versions >= the requires-python of any scripts you install from."],"tags":["python-version","pep723","requirements-from-script","unsupported-python","command-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}