diff --git a/docs/changelog/2050.bugfix.rst b/docs/changelog/2050.bugfix.rst new file mode 100644 index 000000000..4815abf1f --- /dev/null +++ b/docs/changelog/2050.bugfix.rst @@ -0,0 +1,2 @@ +Drop cached python information if the system executable is no longer present (for example when the executable is a +shim and the mapped executable is replaced - such is the case with pyenv) - by :user:`gaborbernat`. diff --git a/src/virtualenv/discovery/cached_py_info.py b/src/virtualenv/discovery/cached_py_info.py index ce79ef14b..7baef386a 100644 --- a/src/virtualenv/discovery/cached_py_info.py +++ b/src/virtualenv/discovery/cached_py_info.py @@ -65,6 +65,10 @@ def _get_via_file_cache(cls, app_data, path, exe): of_path, of_st_mtime, of_content = data["path"], data["st_mtime"], data["content"] if of_path == path_text and of_st_mtime == path_modified: py_info = cls._from_dict({k: v for k, v in of_content.items()}) + sys_exe = py_info.system_executable + if sys_exe is not None and not os.path.exists(sys_exe): + py_info_store.remove() + py_info = None else: py_info_store.remove() if py_info is None: # if not loaded run and save