Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core operator python: check virtualenv is importable by importing #43403

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions airflow/operators/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down