Right now, there's no good way of getting a list of all interpreters in the system. This can be necessary if one wants certain interpreters to be preferred over others (e.g. search for interpreter 3.10-3.14 range, preferring newer versions over older). Also, to make it more convenient for the user, one might want to provide the user with a list of the discovered interpreters that they can choose from.
I feel I should note that it is possible to implement this today with the available public APIs, just in a somewhat hacky way, using predicate callable to populate the list of interpreters:
importosfromtypingimportLiteralfrompackaging.specifiersimportSpecifierSetfrompackaging.versionimportVersionfrompython_discoveryimportPythonInfo, get_interpreterdefget_available_interpreters(requires_python: SpecifierSet) ->list[tuple[str, Version, PythonInfo]]:
interpreters= {}
def_append_interpreter(info: PythonInfo) ->Literal[False]:
version=Version(info.version_str)
ifversioninrequires_python:
# realpath call is needed because get_interpreter lists# /usr/bin and /bin as separate even though they're the same pathinterpreters[os.path.realpath(info.executable)] =inforeturnFalseget_interpreter("cpython", predicate=_append_interpreter)
ret= [(key, *value) forkey, valueininterpreters.items()]
ret.sort(key=itemgetter(1), reverse=True)
returnretNonetheless, I figured it's probably worth making an issue for in case this is something you're interested in explicitly supporting.
Right now, there's no good way of getting a list of all interpreters in the system. This can be necessary if one wants certain interpreters to be preferred over others (e.g. search for interpreter 3.10-3.14 range, preferring newer versions over older). Also, to make it more convenient for the user, one might want to provide the user with a list of the discovered interpreters that they can choose from.
I feel I should note that it is possible to implement this today with the available public APIs, just in a somewhat hacky way, using
predicatecallable to populate the list of interpreters:Nonetheless, I figured it's probably worth making an issue for in case this is something you're interested in explicitly supporting.