diff --git a/python_files/create_venv.py b/python_files/create_venv.py index fd1ff9ab1a47..83106bd889f8 100644 --- a/python_files/create_venv.py +++ b/python_files/create_venv.py @@ -98,11 +98,20 @@ def run_process(args: Sequence[str], error_message: str) -> None: raise VenvError(error_message) from exc +def get_win_venv_path(name: str) -> str: + venv_dir = CWD / name + # If using MSYS2 Python, the Python executable is located in the 'bin' directory. + if file_exists(venv_dir / "bin" / "python.exe"): + return os.fspath(venv_dir / "bin" / "python.exe") + else: + return os.fspath(venv_dir / "Scripts" / "python.exe") + + def get_venv_path(name: str) -> str: # See `venv` doc here for more details on binary location: # https://docs.python.org/3/library/venv.html#creating-virtual-environments if sys.platform == "win32": - return os.fspath(CWD / name / "Scripts" / "python.exe") + return get_win_venv_path(name) else: return os.fspath(CWD / name / "bin" / "python") diff --git a/python_files/tests/test_create_venv.py b/python_files/tests/test_create_venv.py index 72fabdaaecac..6308934d71a0 100644 --- a/python_files/tests/test_create_venv.py +++ b/python_files/tests/test_create_venv.py @@ -122,7 +122,7 @@ def create_gitignore(_p): def test_install_packages(install_type): importlib.reload(create_venv) create_venv.is_installed = lambda _x: True - create_venv.file_exists = lambda x: install_type in x + create_venv.file_exists = lambda x: install_type in str(x) pip_upgraded = False installing = None