From 3585786348c61b0b108bbe399b0d0b9dd920f6f4 Mon Sep 17 00:00:00 2001 From: clearml <> Date: Sun, 22 Jun 2025 22:39:29 +0300 Subject: [PATCH] Fix installing venv from the agent's python binary when the selected python failed - this could be the cause of missing pip or venv in the selected python --- clearml_agent/helper/package/pip_api/venv.py | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/clearml_agent/helper/package/pip_api/venv.py b/clearml_agent/helper/package/pip_api/venv.py index 4e1915b..a904803 100644 --- a/clearml_agent/helper/package/pip_api/venv.py +++ b/clearml_agent/helper/package/pip_api/venv.py @@ -1,3 +1,4 @@ +import sys from typing import Any from ...._vendor.pathlib2 import Path @@ -72,11 +73,21 @@ class VirtualenvPip(SystemPip, PackageManager): self.python, "-m", "virtualenv", self.path, *self.create_flags() ).check_call() except Exception as ex: - # let's try with std library instead - print("WARNING: virtualenv call failed: {}\n INFO: Creating virtual environment with venv".format(ex)) - self.session.command( - self.python, "-m", "venv", self.path, *self.create_flags() - ).check_call() + try: + # let's try with std library instead + print("WARNING: virtualenv call failed: {}\n INFO: Creating virtual environment with venv".format(ex)) + self.session.command( + self.python, "-m", "venv", self.path, *self.create_flags() + ).check_call() + except Exception as ex: + # let's try with std library instead + print("WARNING: virtualenv and venv failed with [{}] trying virtualenv with python [{}]".format( + self.python, sys.executable)) + self.python = str(sys.executable) + self._bin = Path(self.python) + self.session.command( + self.python, "-m", "virtualenv", self.path, *self.create_flags() + ).check_call() return self