2023-02-01 04:46:36 +00:00
|
|
|
# Copyright (c) 2023 Eugene Brodsky (https://github.com/ebr)
|
2023-01-08 08:09:04 +00:00
|
|
|
"""
|
|
|
|
InvokeAI installer script
|
|
|
|
"""
|
|
|
|
|
2023-01-09 05:13:01 +00:00
|
|
|
import os
|
|
|
|
import platform
|
2023-01-16 06:52:22 +00:00
|
|
|
import shutil
|
2023-01-08 08:09:04 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import venv
|
|
|
|
from pathlib import Path
|
2023-01-27 07:10:32 +00:00
|
|
|
from tempfile import TemporaryDirectory
|
2023-01-13 09:11:23 +00:00
|
|
|
from typing import Union
|
2023-01-08 08:09:04 +00:00
|
|
|
|
2023-07-30 14:17:04 +00:00
|
|
|
SUPPORTED_PYTHON = ">=3.9.0,<=3.11.100"
|
2023-02-02 06:18:02 +00:00
|
|
|
INSTALLER_REQS = ["rich", "semver", "requests", "plumbum", "prompt-toolkit"]
|
2023-02-01 03:25:56 +00:00
|
|
|
BOOTSTRAP_VENV_PREFIX = "invokeai-installer-tmp"
|
2023-01-09 05:13:01 +00:00
|
|
|
|
|
|
|
OS = platform.uname().system
|
|
|
|
ARCH = platform.uname().machine
|
|
|
|
VERSION = "latest"
|
2023-01-08 08:09:04 +00:00
|
|
|
|
|
|
|
### Feature flags
|
2023-01-09 05:13:01 +00:00
|
|
|
# Install the virtualenv into the runtime dir
|
2023-01-09 08:09:56 +00:00
|
|
|
FF_VENV_IN_RUNTIME = True
|
2023-01-08 08:09:04 +00:00
|
|
|
|
2023-01-28 21:55:28 +00:00
|
|
|
# Install the wheel packaged with the installer
|
|
|
|
FF_USE_LOCAL_WHEEL = True
|
2023-01-09 08:09:56 +00:00
|
|
|
|
2023-01-08 08:09:04 +00:00
|
|
|
|
|
|
|
class Installer:
|
|
|
|
"""
|
|
|
|
Deploys an InvokeAI installation into a given path
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.reqs = INSTALLER_REQS
|
|
|
|
self.preflight()
|
2023-01-28 08:10:07 +00:00
|
|
|
if os.getenv("VIRTUAL_ENV") is not None:
|
2023-02-04 02:42:00 +00:00
|
|
|
print("A virtual environment is already activated. Please 'deactivate' before installation.")
|
|
|
|
sys.exit(-1)
|
2023-01-28 08:10:07 +00:00
|
|
|
self.bootstrap()
|
2023-01-08 08:09:04 +00:00
|
|
|
|
|
|
|
def preflight(self) -> None:
|
|
|
|
"""
|
|
|
|
Preflight checks
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# verify python version
|
|
|
|
# on macOS verify XCode tools are present
|
|
|
|
# verify libmesa, libglx on linux
|
|
|
|
# check that the system arch is not i386 (?)
|
|
|
|
# check that the system has a GPU, and the type of GPU
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
2023-01-09 05:13:01 +00:00
|
|
|
def mktemp_venv(self) -> TemporaryDirectory:
|
2023-01-08 08:09:04 +00:00
|
|
|
"""
|
|
|
|
Creates a temporary virtual environment for the installer itself
|
|
|
|
|
|
|
|
:return: path to the created virtual environment directory
|
|
|
|
:rtype: TemporaryDirectory
|
|
|
|
"""
|
|
|
|
|
2023-01-14 06:50:11 +00:00
|
|
|
# Cleaning up temporary directories on Windows results in a race condition
|
|
|
|
# and a stack trace.
|
|
|
|
# `ignore_cleanup_errors` was only added in Python 3.10
|
|
|
|
# users of Python 3.9 will see a gnarly stack trace on installer exit
|
2023-01-27 07:10:32 +00:00
|
|
|
if OS == "Windows" and int(platform.python_version_tuple()[1]) >= 10:
|
2023-02-01 03:25:56 +00:00
|
|
|
venv_dir = TemporaryDirectory(prefix=BOOTSTRAP_VENV_PREFIX, ignore_cleanup_errors=True)
|
2023-01-14 06:50:11 +00:00
|
|
|
else:
|
2023-02-01 03:25:56 +00:00
|
|
|
venv_dir = TemporaryDirectory(prefix=BOOTSTRAP_VENV_PREFIX)
|
2023-01-14 06:50:11 +00:00
|
|
|
|
2023-01-08 08:09:04 +00:00
|
|
|
venv.create(venv_dir.name, with_pip=True)
|
|
|
|
self.venv_dir = venv_dir
|
2023-02-01 03:25:56 +00:00
|
|
|
set_sys_path(Path(venv_dir.name))
|
2023-01-09 18:30:34 +00:00
|
|
|
|
2023-01-08 08:09:04 +00:00
|
|
|
return venv_dir
|
|
|
|
|
|
|
|
def bootstrap(self, verbose: bool = False) -> TemporaryDirectory:
|
|
|
|
"""
|
|
|
|
Bootstrap the installer venv with packages required at install time
|
|
|
|
|
|
|
|
:return: path to the virtual environment directory that was bootstrapped
|
|
|
|
:rtype: TemporaryDirectory
|
|
|
|
"""
|
|
|
|
|
2023-01-09 05:13:01 +00:00
|
|
|
print("Initializing the installer. This may take a minute - please wait...")
|
2023-01-08 08:09:04 +00:00
|
|
|
|
2023-01-09 05:13:01 +00:00
|
|
|
venv_dir = self.mktemp_venv()
|
2023-01-30 04:39:14 +00:00
|
|
|
pip = get_pip_from_venv(Path(venv_dir.name))
|
2023-01-08 08:09:04 +00:00
|
|
|
|
2023-02-02 05:28:38 +00:00
|
|
|
cmd = [pip, "install", "--require-virtualenv", "--use-pep517"]
|
2023-01-08 08:09:04 +00:00
|
|
|
cmd.extend(self.reqs)
|
|
|
|
|
|
|
|
try:
|
|
|
|
res = subprocess.check_output(cmd).decode()
|
|
|
|
if verbose:
|
|
|
|
print(res)
|
|
|
|
return venv_dir
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print(e)
|
|
|
|
|
2023-01-09 08:09:56 +00:00
|
|
|
def app_venv(self, path: str = None):
|
|
|
|
"""
|
|
|
|
Create a virtualenv for the InvokeAI installation
|
|
|
|
"""
|
|
|
|
|
|
|
|
# explicit venv location
|
|
|
|
# currently unused in normal operation
|
|
|
|
# useful for testing or special cases
|
|
|
|
if path is not None:
|
|
|
|
venv_dir = Path(path)
|
|
|
|
|
|
|
|
# experimental / testing
|
|
|
|
elif not FF_VENV_IN_RUNTIME:
|
|
|
|
if OS == "Windows":
|
|
|
|
venv_dir_parent = os.getenv("APPDATA", "~/AppData/Roaming")
|
|
|
|
elif OS == "Darwin":
|
|
|
|
# there is no environment variable on macOS to find this
|
|
|
|
# TODO: confirm this is working as expected
|
|
|
|
venv_dir_parent = "~/Library/Application Support"
|
|
|
|
elif OS == "Linux":
|
|
|
|
venv_dir_parent = os.getenv("XDG_DATA_DIR", "~/.local/share")
|
|
|
|
venv_dir = Path(venv_dir_parent).expanduser().resolve() / f"InvokeAI/{VERSION}/venv"
|
|
|
|
|
|
|
|
# stable / current
|
|
|
|
else:
|
|
|
|
venv_dir = self.dest / ".venv"
|
|
|
|
|
2023-02-03 05:36:26 +00:00
|
|
|
# Prefer to copy python executables
|
|
|
|
# so that updates to system python don't break InvokeAI
|
|
|
|
try:
|
|
|
|
venv.create(venv_dir, with_pip=True)
|
|
|
|
# If installing over an existing environment previously created with symlinks,
|
|
|
|
# the executables will fail to copy. Keep symlinks in that case
|
|
|
|
except shutil.SameFileError:
|
|
|
|
venv.create(venv_dir, with_pip=True, symlinks=True)
|
2023-02-02 06:30:47 +00:00
|
|
|
|
|
|
|
# upgrade pip in Python 3.9 environments
|
|
|
|
if int(platform.python_version_tuple()[1]) == 9:
|
|
|
|
from plumbum import FG, local
|
|
|
|
|
|
|
|
pip = local[get_pip_from_venv(venv_dir)]
|
|
|
|
pip["install", "--upgrade", "pip"] & FG
|
|
|
|
|
2023-01-09 08:09:56 +00:00
|
|
|
return venv_dir
|
|
|
|
|
2023-06-28 21:47:04 +00:00
|
|
|
def install(
|
2023-07-29 23:19:42 +00:00
|
|
|
self, root: str = "~/invokeai", version: str = "latest", yes_to_all=False, find_links: Path = None
|
2023-06-28 21:47:04 +00:00
|
|
|
) -> None:
|
2023-01-08 08:09:04 +00:00
|
|
|
"""
|
|
|
|
Install the InvokeAI application into the given runtime path
|
|
|
|
|
2023-01-17 05:47:36 +00:00
|
|
|
:param root: Destination path for the installation
|
|
|
|
:type root: str
|
2023-01-08 08:09:04 +00:00
|
|
|
:param version: InvokeAI version to install
|
|
|
|
:type version: str
|
2023-01-17 05:47:36 +00:00
|
|
|
:param yes: Accept defaults to all questions
|
|
|
|
:type yes: bool
|
2023-02-02 00:03:15 +00:00
|
|
|
:param find_links: A local directory to search for requirement wheels before going to remote indexes
|
|
|
|
:type find_links: Path
|
2023-01-08 08:09:04 +00:00
|
|
|
"""
|
|
|
|
|
2023-01-13 09:11:23 +00:00
|
|
|
import messages
|
2023-01-08 08:09:04 +00:00
|
|
|
|
2023-01-13 09:11:23 +00:00
|
|
|
messages.welcome()
|
2023-01-09 08:09:56 +00:00
|
|
|
|
2023-07-29 23:20:20 +00:00
|
|
|
default_path = os.environ.get("INVOKEAI_ROOT") or Path(root).expanduser().resolve()
|
2023-07-29 20:16:44 +00:00
|
|
|
self.dest = default_path if yes_to_all else messages.dest_path(root)
|
2023-01-08 08:09:04 +00:00
|
|
|
|
2023-01-19 20:34:33 +00:00
|
|
|
# create the venv for the app
|
2023-01-09 08:09:56 +00:00
|
|
|
self.venv = self.app_venv()
|
|
|
|
|
2023-01-27 07:10:32 +00:00
|
|
|
self.instance = InvokeAiInstance(runtime=self.dest, venv=self.venv, version=version)
|
2023-01-09 08:09:56 +00:00
|
|
|
|
2023-01-19 20:34:33 +00:00
|
|
|
# install dependencies and the InvokeAI application
|
2023-02-01 22:41:38 +00:00
|
|
|
(extra_index_url, optional_modules) = get_torch_source() if not yes_to_all else (None, None)
|
|
|
|
self.instance.install(
|
|
|
|
extra_index_url,
|
|
|
|
optional_modules,
|
2023-02-02 00:03:15 +00:00
|
|
|
find_links,
|
2023-02-01 22:41:38 +00:00
|
|
|
)
|
2023-01-10 03:19:38 +00:00
|
|
|
|
2023-01-19 20:34:33 +00:00
|
|
|
# install the launch/update scripts into the runtime directory
|
2023-01-16 06:52:22 +00:00
|
|
|
self.instance.install_user_scripts()
|
|
|
|
|
2023-02-02 00:14:07 +00:00
|
|
|
# run through the configuration flow
|
|
|
|
self.instance.configure()
|
2023-01-08 08:09:04 +00:00
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-01-09 08:09:56 +00:00
|
|
|
class InvokeAiInstance:
|
2023-01-08 08:09:04 +00:00
|
|
|
"""
|
2023-01-09 18:30:34 +00:00
|
|
|
Manages an installed instance of InvokeAI, comprising a virtual environment and a runtime directory.
|
|
|
|
The virtual environment *may* reside within the runtime directory.
|
|
|
|
A single runtime directory *may* be shared by multiple virtual environments, though this isn't currently tested or supported.
|
2023-01-08 08:09:04 +00:00
|
|
|
"""
|
|
|
|
|
2023-01-27 07:10:32 +00:00
|
|
|
def __init__(self, runtime: Path, venv: Path, version: str) -> None:
|
2023-01-09 08:09:56 +00:00
|
|
|
self.runtime = runtime
|
|
|
|
self.venv = venv
|
2023-01-30 04:39:14 +00:00
|
|
|
self.pip = get_pip_from_venv(venv)
|
2023-01-27 07:10:32 +00:00
|
|
|
self.version = version
|
2023-01-09 18:30:34 +00:00
|
|
|
|
2023-02-01 03:25:56 +00:00
|
|
|
set_sys_path(venv)
|
2023-01-09 08:09:56 +00:00
|
|
|
os.environ["INVOKEAI_ROOT"] = str(self.runtime.expanduser().resolve())
|
|
|
|
os.environ["VIRTUAL_ENV"] = str(self.venv.expanduser().resolve())
|
|
|
|
|
|
|
|
def get(self) -> tuple[Path, Path]:
|
|
|
|
"""
|
|
|
|
Get the location of the virtualenv directory for this installation
|
|
|
|
|
|
|
|
:return: Paths of the runtime and the venv directory
|
|
|
|
:rtype: tuple[Path, Path]
|
|
|
|
"""
|
|
|
|
|
|
|
|
return (self.runtime, self.venv)
|
|
|
|
|
2023-02-02 00:03:15 +00:00
|
|
|
def install(self, extra_index_url=None, optional_modules=None, find_links=None):
|
2023-01-13 09:11:23 +00:00
|
|
|
"""
|
2023-02-01 22:41:38 +00:00
|
|
|
Install this instance, including dependencies and the app itself
|
2023-01-13 09:11:23 +00:00
|
|
|
|
|
|
|
:param extra_index_url: the "--extra-index-url ..." line for pip to look in extra indexes.
|
|
|
|
:type extra_index_url: str
|
|
|
|
"""
|
2023-01-09 08:09:56 +00:00
|
|
|
|
2023-01-13 09:11:23 +00:00
|
|
|
import messages
|
2023-01-10 03:19:38 +00:00
|
|
|
|
2023-01-27 07:10:32 +00:00
|
|
|
# install torch first to ensure the correct version gets installed.
|
|
|
|
# works with either source or wheel install with negligible impact on installation times.
|
2023-01-13 09:11:23 +00:00
|
|
|
messages.simple_banner("Installing PyTorch :fire:")
|
2023-02-02 00:03:15 +00:00
|
|
|
self.install_torch(extra_index_url, find_links)
|
2023-01-13 09:11:23 +00:00
|
|
|
|
2023-01-27 07:10:32 +00:00
|
|
|
messages.simple_banner("Installing the InvokeAI Application :art:")
|
2023-02-02 00:03:15 +00:00
|
|
|
self.install_app(extra_index_url, optional_modules, find_links)
|
2023-01-09 18:30:34 +00:00
|
|
|
|
2023-02-02 00:03:15 +00:00
|
|
|
def install_torch(self, extra_index_url=None, find_links=None):
|
2023-01-19 20:34:33 +00:00
|
|
|
"""
|
2023-01-27 07:10:32 +00:00
|
|
|
Install PyTorch
|
2023-01-19 20:34:33 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
from plumbum import FG, local
|
|
|
|
|
|
|
|
pip = local[self.pip]
|
|
|
|
|
2023-01-13 09:11:23 +00:00
|
|
|
(
|
|
|
|
pip[
|
|
|
|
"install",
|
|
|
|
"--require-virtualenv",
|
2023-07-30 14:18:39 +00:00
|
|
|
"numpy~=1.24.0", # choose versions that won't be uninstalled during phase 2
|
2023-07-30 14:17:04 +00:00
|
|
|
"urllib3~=1.26.0",
|
|
|
|
"requests~=2.28.0",
|
2023-05-07 03:09:24 +00:00
|
|
|
"torch~=2.0.0",
|
2023-07-12 02:15:46 +00:00
|
|
|
"torchmetrics==0.11.4",
|
2023-05-07 03:09:24 +00:00
|
|
|
"torchvision>=0.14.1",
|
2023-02-05 18:39:46 +00:00
|
|
|
"--force-reinstall",
|
2023-02-02 00:03:15 +00:00
|
|
|
"--find-links" if find_links is not None else None,
|
|
|
|
find_links,
|
2023-01-27 07:10:32 +00:00
|
|
|
"--extra-index-url" if extra_index_url is not None else None,
|
2023-01-13 09:11:23 +00:00
|
|
|
extra_index_url,
|
|
|
|
]
|
|
|
|
& FG
|
|
|
|
)
|
|
|
|
|
2023-02-02 00:03:15 +00:00
|
|
|
def install_app(self, extra_index_url=None, optional_modules=None, find_links=None):
|
2023-01-13 09:11:23 +00:00
|
|
|
"""
|
2023-01-27 07:10:32 +00:00
|
|
|
Install the application with pip.
|
|
|
|
Supports installation from PyPi or from a local source directory.
|
|
|
|
|
|
|
|
:param extra_index_url: the "--extra-index-url ..." line for pip to look in extra indexes.
|
|
|
|
:type extra_index_url: str
|
2023-02-02 00:03:15 +00:00
|
|
|
|
|
|
|
:param optional_modules: optional modules to install using "[module1,module2]" format.
|
|
|
|
:type optional_modules: str
|
|
|
|
|
|
|
|
:param find_links: path to a directory containing wheels to be searched prior to going to the internet
|
|
|
|
:type find_links: Path
|
2023-01-13 09:11:23 +00:00
|
|
|
"""
|
|
|
|
|
2023-01-28 21:55:28 +00:00
|
|
|
## this only applies to pypi installs; TODO actually use this
|
2023-01-27 07:10:32 +00:00
|
|
|
if self.version == "pre":
|
|
|
|
version = None
|
|
|
|
pre = "--pre"
|
|
|
|
else:
|
|
|
|
version = self.version
|
|
|
|
pre = None
|
|
|
|
|
2023-01-28 21:55:28 +00:00
|
|
|
## TODO: only local wheel will be installed as of now; support for --version arg is TODO
|
|
|
|
if FF_USE_LOCAL_WHEEL:
|
2023-01-30 08:29:05 +00:00
|
|
|
# if no wheel, try to do a source install before giving up
|
|
|
|
try:
|
2023-02-04 00:13:02 +00:00
|
|
|
src = str(next(Path(__file__).parent.glob("InvokeAI-*.whl")))
|
2023-01-30 08:29:05 +00:00
|
|
|
except StopIteration:
|
|
|
|
try:
|
|
|
|
src = Path(__file__).parents[1].expanduser().resolve()
|
|
|
|
# if the above directory contains one of these files, we'll do a source install
|
|
|
|
next(src.glob("pyproject.toml"))
|
2023-03-03 06:34:38 +00:00
|
|
|
next(src.glob("invokeai"))
|
2023-01-30 08:29:05 +00:00
|
|
|
except StopIteration:
|
|
|
|
print("Unable to find a wheel or perform a source install. Giving up.")
|
2023-01-28 21:55:28 +00:00
|
|
|
|
|
|
|
elif version == "source":
|
2023-01-27 07:10:32 +00:00
|
|
|
# this makes an assumption about the location of the installer package in the source tree
|
|
|
|
src = Path(__file__).parents[1].expanduser().resolve()
|
2023-01-28 21:55:28 +00:00
|
|
|
else:
|
2023-02-02 06:00:22 +00:00
|
|
|
# will install from PyPi
|
2023-01-28 21:55:28 +00:00
|
|
|
src = f"invokeai=={version}" if version is not None else "invokeai"
|
2023-01-13 09:11:23 +00:00
|
|
|
|
2023-01-27 07:10:32 +00:00
|
|
|
from plumbum import FG, local
|
2023-01-13 09:11:23 +00:00
|
|
|
|
|
|
|
pip = local[self.pip]
|
|
|
|
|
|
|
|
(
|
|
|
|
pip[
|
|
|
|
"install",
|
|
|
|
"--require-virtualenv",
|
2023-01-27 07:10:32 +00:00
|
|
|
"--use-pep517",
|
2023-02-01 22:41:38 +00:00
|
|
|
str(src) + (optional_modules if optional_modules else ""),
|
2023-02-02 00:03:15 +00:00
|
|
|
"--find-links" if find_links is not None else None,
|
|
|
|
find_links,
|
2023-01-27 07:10:32 +00:00
|
|
|
"--extra-index-url" if extra_index_url is not None else None,
|
2023-01-13 09:11:23 +00:00
|
|
|
extra_index_url,
|
2023-01-27 07:10:32 +00:00
|
|
|
pre,
|
2023-01-13 09:11:23 +00:00
|
|
|
]
|
|
|
|
& FG
|
|
|
|
)
|
2023-01-09 18:30:34 +00:00
|
|
|
|
|
|
|
def configure(self):
|
|
|
|
"""
|
|
|
|
Configure the InvokeAI runtime directory
|
|
|
|
"""
|
|
|
|
|
2023-09-24 19:31:25 +00:00
|
|
|
auto_install = False
|
2023-02-05 18:39:46 +00:00
|
|
|
# set sys.argv to a consistent state
|
2023-02-02 05:28:38 +00:00
|
|
|
new_argv = [sys.argv[0]]
|
|
|
|
for i in range(1, len(sys.argv)):
|
|
|
|
el = sys.argv[i]
|
|
|
|
if el in ["-r", "--root"]:
|
|
|
|
new_argv.append(el)
|
|
|
|
new_argv.append(sys.argv[i + 1])
|
|
|
|
elif el in ["-y", "--yes", "--yes-to-all"]:
|
2023-09-24 19:31:25 +00:00
|
|
|
auto_install = True
|
2023-02-02 05:28:38 +00:00
|
|
|
sys.argv = new_argv
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-09-24 19:31:25 +00:00
|
|
|
import messages
|
2023-09-25 23:18:58 +00:00
|
|
|
import requests # to catch download exceptions
|
2023-01-13 09:09:48 +00:00
|
|
|
|
2023-09-24 19:31:25 +00:00
|
|
|
auto_install = auto_install or messages.user_wants_auto_configuration()
|
|
|
|
if auto_install:
|
2023-09-25 23:18:58 +00:00
|
|
|
sys.argv.append("--yes")
|
2023-09-24 19:31:25 +00:00
|
|
|
else:
|
|
|
|
messages.introduction()
|
2023-01-13 09:09:48 +00:00
|
|
|
|
2023-08-11 00:59:22 +00:00
|
|
|
from invokeai.frontend.install.invokeai_configure import invokeai_configure
|
2023-01-10 03:19:38 +00:00
|
|
|
|
2023-01-17 05:47:36 +00:00
|
|
|
# NOTE: currently the config script does its own arg parsing! this means the command-line switches
|
|
|
|
# from the installer will also automatically propagate down to the config script.
|
|
|
|
# this may change in the future with config refactoring!
|
2023-02-23 00:18:07 +00:00
|
|
|
succeeded = False
|
|
|
|
try:
|
2023-03-03 06:34:38 +00:00
|
|
|
invokeai_configure()
|
2023-02-23 00:18:07 +00:00
|
|
|
succeeded = True
|
2023-02-23 05:43:25 +00:00
|
|
|
except requests.exceptions.ConnectionError as e:
|
|
|
|
print(f"\nA network error was encountered during configuration and download: {str(e)}")
|
2023-02-23 00:18:07 +00:00
|
|
|
except OSError as e:
|
2023-02-23 05:43:25 +00:00
|
|
|
print(f"\nAn OS error was encountered during configuration and download: {str(e)}")
|
2023-02-23 00:18:07 +00:00
|
|
|
except Exception as e:
|
2023-02-23 05:43:25 +00:00
|
|
|
print(f"\nA problem was encountered during the configuration and download steps: {str(e)}")
|
2023-02-23 00:18:07 +00:00
|
|
|
finally:
|
|
|
|
if not succeeded:
|
2023-02-23 05:43:25 +00:00
|
|
|
print('To try again, find the "invokeai" directory, run the script "invoke.sh" or "invoke.bat"')
|
|
|
|
print("and choose option 7 to fix a broken install, optionally followed by option 5 to install models.")
|
2023-02-23 00:18:07 +00:00
|
|
|
print("Alternatively you can relaunch the installer.")
|
2023-01-10 03:19:38 +00:00
|
|
|
|
2023-01-16 06:52:22 +00:00
|
|
|
def install_user_scripts(self):
|
|
|
|
"""
|
|
|
|
Copy the launch and update scripts to the runtime dir
|
|
|
|
"""
|
|
|
|
|
2023-01-27 07:10:32 +00:00
|
|
|
ext = "bat" if OS == "Windows" else "sh"
|
2023-01-16 06:52:22 +00:00
|
|
|
|
2023-02-03 23:14:40 +00:00
|
|
|
# scripts = ['invoke', 'update']
|
|
|
|
scripts = ["invoke"]
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-02-03 23:14:40 +00:00
|
|
|
for script in scripts:
|
2023-02-07 21:35:22 +00:00
|
|
|
src = Path(__file__).parent / ".." / "templates" / f"{script}.{ext}.in"
|
2023-01-16 06:52:22 +00:00
|
|
|
dest = self.runtime / f"{script}.{ext}"
|
2023-01-27 07:10:32 +00:00
|
|
|
shutil.copy(src, dest)
|
2023-01-16 06:52:22 +00:00
|
|
|
os.chmod(dest, 0o0755)
|
|
|
|
|
2023-01-09 18:30:34 +00:00
|
|
|
def update(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def remove(self):
|
|
|
|
pass
|
2023-01-09 08:09:56 +00:00
|
|
|
|
|
|
|
|
2023-01-09 18:30:34 +00:00
|
|
|
### Utility functions ###
|
2023-01-09 08:09:56 +00:00
|
|
|
|
|
|
|
|
2023-01-30 04:39:14 +00:00
|
|
|
def get_pip_from_venv(venv_path: Path) -> str:
|
2023-01-09 18:30:34 +00:00
|
|
|
"""
|
|
|
|
Given a path to a virtual environment, get the absolute path to the `pip` executable
|
|
|
|
in a cross-platform fashion. Does not validate that the pip executable
|
|
|
|
actually exists in the virtualenv.
|
|
|
|
|
|
|
|
:param venv_path: Path to the virtual environment
|
|
|
|
:type venv_path: Path
|
|
|
|
:return: Absolute path to the pip executable
|
|
|
|
:rtype: str
|
|
|
|
"""
|
2023-01-09 08:09:56 +00:00
|
|
|
|
2023-08-17 22:45:25 +00:00
|
|
|
pip = "Scripts\\pip.exe" if OS == "Windows" else "bin/pip"
|
2023-01-27 07:10:32 +00:00
|
|
|
return str(venv_path.expanduser().resolve() / pip)
|
2023-01-09 08:09:56 +00:00
|
|
|
|
|
|
|
|
2023-02-01 03:25:56 +00:00
|
|
|
def set_sys_path(venv_path: Path) -> None:
|
2023-01-09 18:30:34 +00:00
|
|
|
"""
|
2023-02-01 03:25:56 +00:00
|
|
|
Given a path to a virtual environment, set the sys.path, in a cross-platform fashion,
|
|
|
|
such that packages from the given venv may be imported in the current process.
|
|
|
|
Ensure that the packages from system environment are not visible (emulate
|
|
|
|
the virtual env 'activate' script) - this doesn't work on Windows yet.
|
2023-01-09 18:30:34 +00:00
|
|
|
|
|
|
|
:param venv_path: Path to the virtual environment
|
|
|
|
:type venv_path: Path
|
|
|
|
"""
|
|
|
|
|
2023-02-01 03:25:56 +00:00
|
|
|
# filter out any paths in sys.path that may be system- or user-wide
|
|
|
|
# but leave the temporary bootstrap virtualenv as it contains packages we
|
|
|
|
# temporarily need at install time
|
|
|
|
sys.path = list(filter(lambda p: not p.endswith("-packages") or p.find(BOOTSTRAP_VENV_PREFIX) != -1, sys.path))
|
|
|
|
|
|
|
|
# determine site-packages/lib directory location for the venv
|
2023-01-09 18:30:34 +00:00
|
|
|
lib = "Lib" if OS == "Windows" else f"lib/python{sys.version_info.major}.{sys.version_info.minor}"
|
2023-02-01 03:25:56 +00:00
|
|
|
|
|
|
|
# add the site-packages location to the venv
|
2023-01-27 07:10:32 +00:00
|
|
|
sys.path.append(str(Path(venv_path, lib, "site-packages").expanduser().resolve()))
|
2023-01-13 09:11:23 +00:00
|
|
|
|
|
|
|
|
2023-02-01 22:41:38 +00:00
|
|
|
def get_torch_source() -> (Union[str, None], str):
|
2023-01-13 09:11:23 +00:00
|
|
|
"""
|
|
|
|
Determine the extra index URL for pip to use for torch installation.
|
|
|
|
This depends on the OS and the graphics accelerator in use.
|
|
|
|
This is only applicable to Windows and Linux, since PyTorch does not
|
|
|
|
offer accelerated builds for macOS.
|
|
|
|
|
2023-01-19 20:34:33 +00:00
|
|
|
Prefer CUDA-enabled wheels if the user wasn't sure of their GPU, as it will fallback to CPU if possible.
|
2023-01-13 09:11:23 +00:00
|
|
|
|
|
|
|
A NoneType return means just go to PyPi.
|
|
|
|
|
2023-02-01 22:41:38 +00:00
|
|
|
:return: tuple consisting of (extra index url or None, optional modules to load or None)
|
2023-01-13 09:11:23 +00:00
|
|
|
:rtype: list
|
|
|
|
"""
|
|
|
|
|
|
|
|
from messages import graphical_accelerator
|
|
|
|
|
2023-01-19 20:34:33 +00:00
|
|
|
# device can be one of: "cuda", "rocm", "cpu", "idk"
|
2023-01-13 09:11:23 +00:00
|
|
|
device = graphical_accelerator()
|
|
|
|
|
|
|
|
url = None
|
2023-07-29 01:02:48 +00:00
|
|
|
optional_modules = "[onnx]"
|
2023-01-13 09:11:23 +00:00
|
|
|
if OS == "Linux":
|
2023-01-19 20:34:33 +00:00
|
|
|
if device == "rocm":
|
2023-03-31 20:22:00 +00:00
|
|
|
url = "https://download.pytorch.org/whl/rocm5.4.2"
|
2023-01-19 20:34:33 +00:00
|
|
|
elif device == "cpu":
|
2023-01-13 09:11:23 +00:00
|
|
|
url = "https://download.pytorch.org/whl/cpu"
|
|
|
|
|
2023-02-01 22:41:38 +00:00
|
|
|
if device == "cuda":
|
2023-08-09 17:38:58 +00:00
|
|
|
url = "https://download.pytorch.org/whl/cu118"
|
2023-07-29 01:02:48 +00:00
|
|
|
optional_modules = "[xformers,onnx-cuda]"
|
|
|
|
if device == "cuda_and_dml":
|
2023-08-09 17:38:58 +00:00
|
|
|
url = "https://download.pytorch.org/whl/cu118"
|
2023-07-29 01:02:48 +00:00
|
|
|
optional_modules = "[xformers,onnx-directml]"
|
2023-02-01 22:41:38 +00:00
|
|
|
|
2023-01-19 20:34:33 +00:00
|
|
|
# in all other cases, Torch wheels should be coming from PyPi as of Torch 1.13
|
2023-01-13 09:11:23 +00:00
|
|
|
|
2023-02-01 22:41:38 +00:00
|
|
|
return (url, optional_modules)
|