From fc752a4e75810abc781a4b6d89e0392f57a9d887 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sat, 4 Feb 2023 16:14:29 -0500 Subject: [PATCH] move old .venv directory away during install - To ensure a clean environment, the installer will now detect whether a previous .venv exists in the install location, and move it to .venv-backup before creating a fresh .venv. - Any previous .venv-backup is deleted. - User is informed of process. --- installer/installer.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/installer/installer.py b/installer/installer.py index dfdc21730e..066b5bbf87 100644 --- a/installer/installer.py +++ b/installer/installer.py @@ -130,10 +130,24 @@ class Installer: else: venv_dir = self.dest / ".venv" + # if there is an existing venv directory, then we move it out of the way + # to create a clean install + if venv_dir.exists(): + backup_venv = self.dest / ".venv-backup" + print(f"Previous .venv directory detected. Renaming to {backup_venv}",end='') + if backup_venv.exists(): + print(f' and removing existing {backup_venv} directory',end='') + shutil.rmtree(backup_venv) + venv_dir.replace(backup_venv) + print('') + # Prefer to copy python executables # so that updates to system python don't break InvokeAI try: venv.create(venv_dir, with_pip=True) + # Because we moved away the previous .venv, the following code + # isn't strictly necessary, but keeping it here in case we decide + # it better to upgrade an existing venv rather than replace. # If installing over an existing environment previously created with symlinks, # the executables will fail to copy. Keep symlinks in that case except shutil.SameFileError: