From f7af1642c6a11a70b0c3b79da0a3a100c6f80618 Mon Sep 17 00:00:00 2001 From: Akegarasu Date: Mon, 9 Sep 2024 23:03:01 +0800 Subject: [PATCH] script --- install-cn.ps1 | 33 ++++++++++++++++++++------------- run_gui.ps1 | 13 +++++++++++-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/install-cn.ps1 b/install-cn.ps1 index 286bcde..9b1c5ab 100644 --- a/install-cn.ps1 +++ b/install-cn.ps1 @@ -17,31 +17,38 @@ function Check { InstallFail } } - -if (!(Test-Path -Path "venv")) { - Write-Output "正在创建虚拟环境..." - python -m venv venv - Check "创建虚拟环境失败,请检查 python 是否安装完毕以及 python 版本是否为64位版本的python 3.10、或python的目录是否在环境变量PATH内。" +if (Test-Path -Path "python\python.exe") { + Write-Output "使用 python 文件夹内的 python..." + $py_path = (Get-Item "python").FullName + $env:PATH = "$py_path;$env:PATH" +} +else { + if (!(Test-Path -Path "venv")) { + Write-Output "正在创建虚拟环境..." + python -m venv venv + Check "创建虚拟环境失败,请检查 python 是否安装完毕以及 python 版本是否为64位版本的python 3.10、或python的目录是否在环境变量PATH内。" + } + + Write-Output "检测到虚拟环境,尝试激活..." + .\venv\Scripts\activate + Check "激活虚拟环境失败。" } - -.\venv\Scripts\activate -Check "激活虚拟环境失败。" Set-Location .\scripts Write-Output "安装程序所需依赖 (已进行国内加速,若在国外或无法使用加速源请换用 install.ps1 脚本)" $install_torch = Read-Host "是否需要安装 Torch+xformers? [y/n] (默认为 y)" -if ($install_torch -eq "y" -or $install_torch -eq "Y" -or $install_torch -eq ""){ - pip install torch==2.4.0+cu121 torchvision==0.19.0+cu121 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html +if ($install_torch -eq "y" -or $install_torch -eq "Y" -or $install_torch -eq "") { + python -m pip install torch==2.4.0+cu121 torchvision==0.19.0+cu121 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html Check "torch 安装失败,请删除 venv 文件夹后重新运行。" - pip install -U -I --no-deps xformers==0.0.27.post2 + python -m pip install -U -I --no-deps xformers==0.0.27.post2 Check "xformers 安装失败。" } -pip install --upgrade -r requirements.txt +python -m pip install --upgrade -r requirements.txt Check "sd-scripts 依赖安装失败。" Set-Location .. -pip install --upgrade -r requirements.txt +python -m pip install --upgrade -r requirements.txt Check "训练界面依赖安装失败。" Write-Output "安装完毕" diff --git a/run_gui.ps1 b/run_gui.ps1 index 39ac7a9..49040b7 100644 --- a/run_gui.ps1 +++ b/run_gui.ps1 @@ -1,6 +1,15 @@ -.\venv\Scripts\activate - $Env:HF_HOME = "huggingface" $Env:PYTHONUTF8 = "1" +if (Test-Path -Path "venv\Scripts\activate") { + Write-Host -ForegroundColor green "Activating virtual environment..." + .\venv\Scripts\activate +} +elseif (Test-Path -Path "python\python.exe") { + Write-Host -ForegroundColor green "Using python from python folder..." +} +else { + Write-Host -ForegroundColor Blue "No virtual environment found, using system python..." +} + python gui.py \ No newline at end of file