diff --git a/airflow/operators/python.py b/airflow/operators/python.py index b032b45ed3e6e..de795bf8dd43e 100644 --- a/airflow/operators/python.py +++ b/airflow/operators/python.py @@ -68,13 +68,16 @@ def is_venv_installed() -> bool: """ - Check if the virtualenv package is installed via checking if it is on the path or installed as package. + Check if the virtualenv package is installed by importing `virtualenv`. - :return: True if it is. Whichever way of checking it works, is fine. + :return: True if no `ModuleNotFoundError` is raised, False otherwise. """ - if shutil.which("virtualenv") or importlib.util.find_spec("virtualenv"): + try: + import virtualenv return True - return False + except ModuleNotFoundError: + return False + def task(python_callable: Callable | None = None, multiple_outputs: bool | None = None, **kwargs):