загрузка на ноуте
This commit is contained in:
1 parent
c5aed5b970
commit
9992030ab3
1 file changed
+18
-29
@@ -1,5 +1,5 @@
|
||||
# Установка и запуск симулятора (вызывается из УСТАНОВИТЬ_И_ЗАПУСТИТЬ.bat).
|
||||
# 1) Python 3.11+: если нет — ставится через winget, только для текущего пользователя
|
||||
# 1) Python 3.10+: если нет — ставится через winget, только для текущего пользователя
|
||||
# 2) библиотеки программы — в папку .venv рядом, в систему ничего не ставится
|
||||
# 3) запуск: страница http://127.0.0.1:8765 открывается в браузере
|
||||
# Параметр /install-only — только установить.
|
||||
@@ -12,27 +12,26 @@ $Host.UI.RawUI.WindowTitle = "Симулятор"
|
||||
$VenvPy = Join-Path $Dir ".venv\Scripts\python.exe"
|
||||
$VenvPyw = Join-Path $Dir ".venv\Scripts\pythonw.exe"
|
||||
|
||||
function Test-Python($Executable) {
|
||||
try {
|
||||
& $Executable -c "import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)" 2>$null
|
||||
return $LASTEXITCODE -eq 0
|
||||
} catch { return $false }
|
||||
}
|
||||
|
||||
function Find-Python {
|
||||
foreach ($v in "3.13", "3.12", "3.11") {
|
||||
foreach ($v in "3.13", "3.12", "3.11", "3.10") {
|
||||
try {
|
||||
$exe = & py "-$v" -c "import sys; print(sys.executable)" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $exe -and (Test-Python $exe.Trim())) { return $exe.Trim() }
|
||||
$exe = & py "-$v" -c "import sys, json; print(json.dumps(sys.executable, ensure_ascii=True))" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $exe) {
|
||||
$path = $exe | ConvertFrom-Json
|
||||
if (Test-Path -LiteralPath $path -PathType Leaf) { return $path }
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
foreach ($d in "Python313", "Python312", "Python311") {
|
||||
foreach ($d in "Python313", "Python312", "Python311", "Python310") {
|
||||
$p = Join-Path $env:LOCALAPPDATA "Programs\Python\$d\python.exe"
|
||||
if ((Test-Path $p) -and (Test-Python $p)) { return $p }
|
||||
if (Test-Path $p) { return $p }
|
||||
}
|
||||
try {
|
||||
$exe = & python -c "import sys; assert sys.version_info >= (3, 11); print(sys.executable)" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $exe -and (Test-Python $exe.Trim())) { return $exe.Trim() }
|
||||
$exe = & python -c "import sys, json; assert sys.version_info >= (3, 10); print(json.dumps(sys.executable, ensure_ascii=True))" 2>$null
|
||||
if ($LASTEXITCODE -eq 0 -and $exe) {
|
||||
$path = $exe | ConvertFrom-Json
|
||||
if (Test-Path -LiteralPath $path -PathType Leaf) { return $path }
|
||||
}
|
||||
} catch {}
|
||||
return $null
|
||||
}
|
||||
@@ -43,8 +42,7 @@ function Fail($text) {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not (Test-Python $VenvPy)) {
|
||||
Write-Host "Окружение отсутствует или не работает. Подбираю Python 3.11+..." -ForegroundColor Yellow
|
||||
if (-not (Test-Path $VenvPy)) {
|
||||
$py = Find-Python
|
||||
if (-not $py) {
|
||||
Write-Host "Python не найден. Ставлю Python 3.12 через winget..." -ForegroundColor Yellow
|
||||
@@ -56,23 +54,14 @@ if (-not (Test-Python $VenvPy)) {
|
||||
$py = Find-Python
|
||||
if (-not $py) { Fail "Python установлен, но ещё не виден. Закройте окно и запустите файл ещё раз." }
|
||||
}
|
||||
$VenvDir = Join-Path $Dir ".venv"
|
||||
if (Test-Path $VenvDir) {
|
||||
$Backup = ".venv.backup-" + [Guid]::NewGuid().ToString("N")
|
||||
Rename-Item -LiteralPath $VenvDir -NewName $Backup
|
||||
Write-Host "Старое окружение сохранено: $Backup"
|
||||
}
|
||||
Write-Host "Python: $py"
|
||||
Write-Host "Создаю окружение программы (.venv)..."
|
||||
& $py -m venv (Join-Path $Dir ".venv")
|
||||
if ($LASTEXITCODE -ne 0 -or -not (Test-Path $VenvPy)) { Fail "Не удалось создать .venv" }
|
||||
}
|
||||
|
||||
if (-not (Test-Python $VenvPy)) {
|
||||
Fail "Не удалось запустить Python из нового окружения .venv."
|
||||
}
|
||||
Write-Host "Проверяю библиотеки. Ниже отображается ход установки; для загрузки нужен интернет..."
|
||||
& $VenvPy -m pip install --disable-pip-version-check --timeout 30 --retries 2 -r (Join-Path $Dir "requirements.txt")
|
||||
Write-Host "Проверяю библиотеки..."
|
||||
& $VenvPy -m pip install --disable-pip-version-check -q -r (Join-Path $Dir "requirements.txt")
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Fail "Не удалось установить библиотеки. Проверьте интернет (и VPN, если сайты у вас заблокированы) и запустите ещё раз."
|
||||
}
|
||||
@@ -85,6 +74,6 @@ Write-Host ""
|
||||
Write-Host "Запускаю симулятор. Страница: http://127.0.0.1:8765" -ForegroundColor Green
|
||||
Write-Host "Это окно — движок программы: не закрывайте его, пока пользуетесь симулятором."
|
||||
Write-Host ""
|
||||
Start-Process -FilePath $VenvPyw -ArgumentList "web_proxy.py" -WorkingDirectory $Dir -WindowStyle Hidden
|
||||
Start-Process -FilePath $VenvPyw -ArgumentList "web_proxy.py" -WorkingDirectory $Dir
|
||||
Start-Process "http://127.0.0.1:8765"
|
||||
& $VenvPy web_sim.py --backend
|
||||
Reference in new issue
Block a user