Skip to content

Check if virtualenv is installed fails #24783

Description

@nanohanno

Apache Airflow version

2.3.0

What happened

When using a PythonVirtualenvOperator it is checked if virtualenv is installed by
if not shutil.which("virtualenv"):

if not shutil.which("virtualenv"):

Actually, this expression checks if virtualenv is on PATH. If Airflow is installed in a virtual environment itself and virtualenv is not installed in the environment the check might pass but virtualenv cannot be used as it is not present in the environment.

What you think should happen instead

It should be checked if virtualenv is actually available in the environment.

if importlib.util.find_spec("virtualenv") is None:
    raise AirflowException('PythonVirtualenvOperator requires virtualenv, please install it.')

https://stackoverflow.com/a/14050282

How to reproduce

No response

Operating System

Ubuntu 20.04

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions