From b12c8a28d7c98f47f9b74d5cccbcea63bb168bb8 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 12 Oct 2022 22:15:38 +0530 Subject: [PATCH] Updated the installer to simplify the use of micromamba, and use conda for the actual installation; Update conda during the update script --- installer/How to create the installers.md | 12 ++-- installer/install.bat | 67 +++++++++++----------- installer/install.sh | 70 +++++++++++++---------- invoke.bat | 26 ++------- invoke.sh | 23 ++------ update.bat | 2 + update.sh | 8 ++- 7 files changed, 96 insertions(+), 112 deletions(-) diff --git a/installer/How to create the installers.md b/installer/How to create the installers.md index 7089f7929a..9b76c61aba 100644 --- a/installer/How to create the installers.md +++ b/installer/How to create the installers.md @@ -18,34 +18,34 @@ The download link provides tar.bz2 files. # Create the installer Create the following folder structure, and zip it up. -For Linux/Mac: Make sure the `chmod u+x` permission is granted to `installer.sh` and the corresponding `micromamba` binary. +For Linux/Mac: Make sure the `chmod u+x` permission is granted to `install.sh` and the corresponding `micromamba` binary. ### Windows x64: ``` -.\installer.bat +.\install.bat .\installer_files\micromamba_win_x64.exe ``` ### Linux x64: ``` -.\installer.sh +.\install.sh .\installer_files\micromamba_linux_x64 ``` ### Linux arm64: ``` -.\installer.sh +.\install.sh .\installer_files\micromamba_linux_arm64 ``` ### Mac x64: ``` -.\installer.sh +.\install.sh .\installer_files\micromamba_mac_x64 ``` ### Mac arm64 (M1/Apple Silicon): ``` -.\installer.sh +.\install.sh .\installer_files\micromamba_mac_arm64 ``` \ No newline at end of file diff --git a/installer/install.bat b/installer/install.bat index 82af2b2ab7..e2c8260114 100644 --- a/installer/install.bat +++ b/installer/install.bat @@ -1,13 +1,13 @@ @echo off -@rem This script will install git and python (if not found on the PATH variable) +@rem This script will install git and conda (if not found on the PATH variable) @rem using micromamba (an 8mb static-linked single-file binary, conda replacement). -@rem For users who already have git and python, this step will be skipped. +@rem For users who already have git and conda, this step will be skipped. @rem Next, it'll checkout the project's git repo, if necessary. @rem Finally, it'll create the conda environment and preload the models. -@rem This enables a user to install this project without manually installing python and git. +@rem This enables a user to install this project without manually installing conda and git. @rem prevent the window from closing after an error if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit ) @@ -16,51 +16,43 @@ if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit ) set MAMBA_ROOT_PREFIX=%cd%\installer_files\mamba set INSTALL_ENV_DIR=%cd%\installer_files\env set MICROMAMBA_BINARY_FILE=%cd%\installer_files\micromamba_win_x64.exe -set PATH=%PATH%;%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts -@rem figure out whether git and python needs to be installed +@rem figure out whether git and conda needs to be installed set PACKAGES_TO_INSTALL= -call python --version "" >tmp/stdout.txt 2>tmp/stderr.txt -if "%ERRORLEVEL%" NEQ "0" set PACKAGES_TO_INSTALL=%PACKAGES_TO_INSTALL% python +call conda --version "" >tmp/stdout.txt 2>tmp/stderr.txt +if "%ERRORLEVEL%" NEQ "0" set PACKAGES_TO_INSTALL=%PACKAGES_TO_INSTALL% conda call git --version "" >tmp/stdout.txt 2>tmp/stderr.txt if "%ERRORLEVEL%" NEQ "0" set PACKAGES_TO_INSTALL=%PACKAGES_TO_INSTALL% git -@rem initialize micromamba -if not exist "%MAMBA_ROOT_PREFIX%" ( - mkdir "%MAMBA_ROOT_PREFIX%" - copy "%MICROMAMBA_BINARY_FILE%" "%MAMBA_ROOT_PREFIX%\micromamba.exe" - - @rem test the mamba binary - echo Micromamba version: - call "%MAMBA_ROOT_PREFIX%\micromamba.exe" --version - - @rem run the shell hook, otherwise activate will fail - if not exist "%MAMBA_ROOT_PREFIX%\Scripts" ( - call "%MAMBA_ROOT_PREFIX%\micromamba.exe" shell hook --log-level 4 -s cmd.exe - ) -) - -call "%MAMBA_ROOT_PREFIX%\condabin\mamba_hook.bat" - -@rem (if necessary) install git and python into a contained environment +@rem (if necessary) install git and conda into a contained environment if "%PACKAGES_TO_INSTALL%" NEQ "" ( - echo "Packages to install: %PACKAGES_TO_INSTALL%" + @rem initialize micromamba + if not exist "%MAMBA_ROOT_PREFIX%" ( + mkdir "%MAMBA_ROOT_PREFIX%" + copy "%MICROMAMBA_BINARY_FILE%" "%MAMBA_ROOT_PREFIX%\micromamba.exe" - @rem install git and python into the installer env - if not exist "%INSTALL_ENV_DIR%" ( - call micromamba create -y --prefix "%INSTALL_ENV_DIR%" + @rem test the mamba binary + echo Micromamba version: + call "%MAMBA_ROOT_PREFIX%\micromamba.exe" --version ) - call micromamba install -y --prefix "%INSTALL_ENV_DIR%" -c conda-forge %PACKAGES_TO_INSTALL% + @rem create the installer env + if not exist "%INSTALL_ENV_DIR%" ( + call "%MAMBA_ROOT_PREFIX%\micromamba.exe" create -y --prefix "%INSTALL_ENV_DIR%" + ) - @rem activate - call micromamba activate "%INSTALL_ENV_DIR%" + echo "Packages to install:%PACKAGES_TO_INSTALL%" + + call "%MAMBA_ROOT_PREFIX%\micromamba.exe" install -y --prefix "%INSTALL_ENV_DIR%" -c conda-forge %PACKAGES_TO_INSTALL% ) +set PATH=%PATH%;%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts + @rem get the repo (and load into the current directory) if not exist ".git" ( + call git config --global init.defaultBranch main call git init call git remote add origin https://github.com/cmdr2/InvokeAI.git call git fetch @@ -68,8 +60,8 @@ if not exist ".git" ( ) @rem create the environment -call micromamba create -y -f environment.yml -call micromamba activate invokeai +call conda env create +call conda activate invokeai @rem preload the models call python scripts\preload_models.py @@ -77,4 +69,11 @@ call python scripts\preload_models.py @rem make the models dir mkdir models\ldm\stable-diffusion-v1 +@rem tell the user that they need to download the ckpt +echo. +echo "Now you need to install the weights for the stable diffusion model." +echo "Please follow the steps at https://invoke-ai.github.io/InvokeAI/installation/INSTALL_WINDOWS/ to complete the installation" + +@rem it would be nice if the weights downloaded automatically, and didn't need the user to do this manually. + pause diff --git a/installer/install.sh b/installer/install.sh index 5edf465902..005e3f80e1 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -1,13 +1,13 @@ #!/bin/bash -# This script will install git and python (if not found on the PATH variable) +# This script will install git and conda (if not found on the PATH variable) # using micromamba (an 8mb static-linked single-file binary, conda replacement). -# For users who already have git and python, this step will be skipped. +# For users who already have git and conda, this step will be skipped. # Next, it'll checkout the project's git repo, if necessary. # Finally, it'll create the conda environment and preload the models. -# This enables a user to install this project without manually installing python and git. +# This enables a user to install this project without manually installing conda and git. OS_NAME=$(uname -s) case "${OS_NAME}" in @@ -27,42 +27,40 @@ esac export MAMBA_ROOT_PREFIX="$(pwd)/installer_files/mamba" INSTALL_ENV_DIR="$(pwd)/installer_files/env" MICROMAMBA_BINARY_FILE="$(pwd)/installer_files/micromamba_${OS_NAME}_${OS_ARCH}" -if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$PATH;$INSTALL_ENV_DIR/bin"; fi -# figure out what needs to be installed +# figure out whether git and conda needs to be installed PACKAGES_TO_INSTALL="" -if ! hash "python" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL python"; fi +if ! hash "conda" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL conda"; fi if ! hash "git" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL git"; fi -# initialize micromamba -mkdir -p "$MAMBA_ROOT_PREFIX" -cp "$MICROMAMBA_BINARY_FILE" "$MAMBA_ROOT_PREFIX/micromamba" - -# test the mamba binary -echo Micromamba version: -"$MAMBA_ROOT_PREFIX/micromamba" --version - -# run the shell hook, otherwise activate will fail -eval "$($MAMBA_ROOT_PREFIX/micromamba shell hook -s posix)" - -# install git and python into a contained environment (if necessary) +# (if necessary) install git and conda into a contained environment if [ "$PACKAGES_TO_INSTALL" != "" ]; then - echo "Packages to install: $PACKAGES_TO_INSTALL" + # initialize micromamba + if [ ! -e "$MAMBA_ROOT_PREFIX" ]; then + mkdir -p "$MAMBA_ROOT_PREFIX" + cp "$MICROMAMBA_BINARY_FILE" "$MAMBA_ROOT_PREFIX/micromamba" - # install git and python into the installer env - if [ ! -e "$INSTALL_ENV_DIR" ]; then - micromamba create -y --prefix "$INSTALL_ENV_DIR" + # test the mamba binary + echo "Micromamba version:" + "$MAMBA_ROOT_PREFIX/micromamba" --version fi - micromamba install -y --prefix "$INSTALL_ENV_DIR" -c conda-forge $PACKAGES_TO_INSTALL + # create the installer env + if [ ! -e "$INSTALL_ENV_DIR" ]; then + "$MAMBA_ROOT_PREFIX/micromamba" create -y --prefix "$INSTALL_ENV_DIR" + fi - # activate - micromamba activate "$INSTALL_ENV_DIR" + echo "Packages to install:$PACKAGES_TO_INSTALL" + + "$MAMBA_ROOT_PREFIX/micromamba" install -y --prefix "$INSTALL_ENV_DIR" -c conda-forge $PACKAGES_TO_INSTALL fi +if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$PATH;$INSTALL_ENV_DIR/bin"; fi + # get the repo (and load into the current directory) -if [ ! -e ".git" ]; then +if [ ! -e ".git"]; then + git config --global init.defaultBranch main git init git remote add origin https://github.com/cmdr2/InvokeAI.git git fetch @@ -71,15 +69,27 @@ fi # create the environment if [ "$OS_NAME" == "mac" ]; then - PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-arm64 micromamba create -y -f environment-mac.yml + PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-arm64 conda env create -y -f environment-mac.yml else - micromamba create -y -f environment.yml + conda env create -y -f environment.yml fi -micromamba activate invokeai +conda activate invokeai # preload the models python scripts/preload_models.py # make the models dir -mkdir -p models/ldm/stable-diffusion-v1 +mkdir models/ldm/stable-diffusion-v1 + +# tell the user that they need to download the ckpt +WEIGHTS_DOC_URL="https://invoke-ai.github.io/InvokeAI/installation/INSTALL_LINUX/" +if [ "$OS_NAME" == "mac" ]; then + WEIGHTS_DOC_URL="https://invoke-ai.github.io/InvokeAI/installation/INSTALL_MAC/" +fi + +echo. +echo "Now you need to install the weights for the stable diffusion model." +echo "Please follow the steps at $WEIGHTS_DOC_URL to complete the installation" + +# it would be nice if the weights downloaded automatically, and didn't need the user to do this manually. diff --git a/invoke.bat b/invoke.bat index ac5bcc4500..ff96fcd4fb 100644 --- a/invoke.bat +++ b/invoke.bat @@ -3,27 +3,9 @@ @rem prevent the window from closing after running the commands if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit ) -@rem check if conda exists, otherwise use micromamba -set CONDA_COMMAND=conda +set INSTALL_ENV_DIR=%cd%\installer_files\env +set PATH=%PATH%;%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts -call conda --version "" >tmp/stdout.txt 2>tmp/stderr.txt -if "%ERRORLEVEL%" NEQ "0" set CONDA_COMMAND=micromamba +call conda activate invokeai -@rem initialize micromamba, if using that -if "%CONDA_COMMAND%" EQU "micromamba" ( - set MAMBA_ROOT_PREFIX=%cd%\installer_files\mamba - set INSTALL_ENV_DIR=%cd%\installer_files\env - - if not exist "%MAMBA_ROOT_PREFIX%\condabin" ( - echo "Have you run install.bat?" - exit /b - ) - - call "%MAMBA_ROOT_PREFIX%\condabin\mamba_hook.bat" - - call micromamba activate "%INSTALL_ENV_DIR%" -) - -call %CONDA_COMMAND% activate invokeai - -pause +echo Ready to dream.. diff --git a/invoke.sh b/invoke.sh index e999923f40..639b66233a 100755 --- a/invoke.sh +++ b/invoke.sh @@ -1,27 +1,12 @@ #!/bin/bash if [ "$0" == "bash" ]; then - # check if conda exists, otherwise use micromamba - CONDA_COMMAND="conda" + INSTALL_ENV_DIR="$(pwd)/installer_files/env" + if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$PATH;$INSTALL_ENV_DIR/bin"; fi - if ! hash "conda" &>/dev/null; then CONDA_COMMAND="micromamba"; fi + conda activate invokeai - # initialize micromamba, if using that - if [ "$CONDA_COMMAND" == "micromamba" ]; then - export MAMBA_ROOT_PREFIX="$(pwd)/installer_files/mamba" - INSTALL_ENV_DIR="$(pwd)/installer_files/env" - - if [ ! -e "$MAMBA_ROOT_PREFIX" ]; then - echo "Have you run install.sh?" - exit - fi - - eval "$($MAMBA_ROOT_PREFIX/micromamba shell hook -s posix)" - - micromamba activate "$INSTALL_ENV_DIR" - ) - - $CONDA_COMMAND activate invokeai + echo "Ready to dream.." else bash --init-file invoke.sh fi diff --git a/update.bat b/update.bat index f346dce3e6..cfffd80d51 100644 --- a/update.bat +++ b/update.bat @@ -8,4 +8,6 @@ if exist ".git" ( call git pull ) +conda env update + pause \ No newline at end of file diff --git a/update.sh b/update.sh index 7ec5bfcb8e..3e82f419ff 100755 --- a/update.sh +++ b/update.sh @@ -1,10 +1,16 @@ #!/bin/bash INSTALL_ENV_DIR="$(pwd)/installer_files/env" - if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$PATH;$INSTALL_ENV_DIR/bin"; fi # update the repo if [ -e ".git" ]; then git pull fi + +OS_NAME=$(uname -s) +case "${OS_NAME}" in + Linux*) conda env update;; + Darwin*) conda env update -f environment-mac.yml;; + *) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit +esac