From bbc5009e9f77db520c74f728909259f1325f5af8 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Mon, 10 Oct 2022 12:20:46 +0200 Subject: [PATCH] Tools: Check venv the same way how it will be used later It is possible that import of venv passes but it still cannot be started. This can happen with the embedded Python deployed by the ESP-IDF installer. --- tools/idf_tools.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/idf_tools.py b/tools/idf_tools.py index a388bbdb5f97..a422e8f4af24 100755 --- a/tools/idf_tools.py +++ b/tools/idf_tools.py @@ -1983,9 +1983,7 @@ def action_install_python_env(args): # type: ignore venv_can_upgrade = False if not os.path.exists(virtualenv_python): - try: - import venv # noqa: F401 - + if subprocess.run([sys.executable, '-m', 'venv', '-h'], check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0: # venv available virtualenv_options = ['--clear'] # delete environment if already exists if sys.version_info[:2] >= (3, 9): @@ -1998,7 +1996,7 @@ def action_install_python_env(args): # type: ignore *virtualenv_options, idf_python_env_path], stdout=sys.stdout, stderr=sys.stderr) - except ImportError: + else: # The embeddable Python for Windows doesn't have the built-in venv module install_legacy_python_virtualenv(idf_python_env_path)