{"id":"9a4677dd6d0e11a5","repo":"python-poetry/poetry","slug":"the-specified-python-version-given-is-not-supp","errorCode":null,"errorMessage":"The specified Python version ({given}) is not supported by the project ({expected}).","messagePattern":"The specified Python version \\((.+?)\\) is not supported by the project \\((.+?)\\)\\.","errorType":"validation","errorClass":"NoCompatiblePythonVersionFoundError","httpStatus":null,"severity":"error","filePath":"src/poetry/utils/env/env_manager.py","lineNumber":427,"sourceCode":"            )\n\n        venv_path = (\n            self.in_project_venv\n            if in_project_venv\n            else self._poetry.config.virtualenvs_path\n        )\n        if not name:\n            name = self._poetry.package.name\n\n        if not supported_python.allows(python.patch_version):\n            # The currently activated or chosen Python version\n            # is not compatible with the Python constraint specified\n            # for the project.\n            # If an executable has been specified, we stop there\n            # and notify the user of the incompatibility.\n            # Otherwise, we try to find a compatible Python version.\n            if specific_python_requested:\n                raise NoCompatiblePythonVersionFoundError(\n                    self._poetry.package.python_versions,\n                    python.patch_version.to_string(),\n                )\n\n            self._io.write_error_line(\n                f\"<warning>The currently activated Python version {python.patch_version.to_string()} is not\"\n                f\" supported by the project ({self._poetry.package.python_versions}).\\n\"\n                \"Trying to find and use a compatible version.</warning> \"\n            )\n\n            python = Python.get_compatible_python(poetry=self._poetry, io=self._io)\n\n        if in_project_venv:\n            venv = venv_path\n        else:\n            name = self.generate_env_name(name, str(cwd))\n            name = f\"{name}-py{python.minor_version.to_string()}\"\n            venv = venv_path / name","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/utils/env/env_manager.py#L409-L445","documentation":"Raised as NoCompatiblePythonVersionFoundError (with a 'given' version) in EnvManager.create_venv when a specific Python was explicitly requested (the python argument is not None) but its patch version fails the project's python constraint. Unlike the auto-resolve path, Poetry stops immediately because the user explicitly chose this interpreter.","triggerScenarios":"Calling create_venv(python=<Python instance>) (e.g. via 'poetry env use <python>') where python.patch_version is not allowed by the package's python_constraint. Exact branch: env_manager.py:419-430.","commonSituations":"'poetry env use python3.8' on a project that declares python = \">=3.10\"; pinning to an interpreter that the project's CI matrix doesn't support; mismatched python constraints after bumping the project's min version.","solutions":["Pick an interpreter version that satisfies the constraint in pyproject.toml.","Loosen the python constraint in [tool.poetry.dependencies] to include the requested version.","List available interpreters and choose: 'poetry env use' with a compliant one.","Confirm the requested version string is what you think (full patch vs minor)."],"exampleFix":"// before - project declares python = \">=3.10\"\nmanager.activate(\"python3.8\")  # -> NoCompatiblePythonVersionFoundError\n\n// after - use a compliant interpreter or widen the constraint\nmanager.activate(\"python3.11\")","handlingStrategy":"validation","validationCode":"from poetry.utils.env.python import Python\n\ndef requested_python_allowed(poetry, python_name: str) -> bool:\n    inst = Python.get_by_name(python_name)\n    if inst is None:\n        return False\n    return poetry.package.python_constraint.allows(inst.patch_version)","typeGuard":"from poetry.utils.env.python.exceptions import NoCompatiblePythonVersionFoundError, PythonVersionError\n\ndef is_no_compatible_python(e: Exception) -> bool:\n    return isinstance(e, NoCompatiblePythonVersionFoundError) or (\n        isinstance(e, PythonVersionError) and \"not supported by the project\" in str(e)\n    )","tryCatchPattern":"from poetry.utils.env.python.exceptions import NoCompatiblePythonVersionFoundError\n\ntry:\n    manager.activate(\"python3.8\")\nexcept NoCompatiblePythonVersionFoundError:\n    # either pick a compliant interpreter or widen the constraint\n    raise SystemExit(\"choose a python allowed by [tool.poetry.dependencies] python\")","preventionTips":["Check the python constraint in pyproject.toml before running 'poetry env use'.","Prefer letting Poetry auto-resolve (omit the explicit interpreter) when unsure.","Loosen the constraint if the requested version is genuinely acceptable.","Validate the interpreter's patch version against the constraint programmatically."],"tags":["python-constraint","env-use","create-venv","pyproject"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}