Skip to content

utils_python_interpreter

get_python_interpreter(python_version, resource)

Return the path to the Python interpreter

Parameters:

Name Type Description Default
python_version str

Python version

required

Raises:

Type Description
ValueError

If the python version requested is not available on the host.

Returns:

Name Type Description
interpreter str

string representing the python executable or its path

Source code in fractal_server/tasks/v2/utils_python_interpreter.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def get_python_interpreter(
    python_version: str,
    resource: Resource,
) -> str:
    """
    Return the path to the Python interpreter

    Args:
        python_version: Python version

    Raises:
        ValueError: If the python version requested is not available on the
                    host.

    Returns:
        interpreter: string representing the python executable or its path
    """

    python_path = resource.tasks_python_config["versions"].get(python_version)
    if python_path is None:
        raise ValueError(f"Requested {python_version=} is not available.")
    return python_path