Инструменты пользователя

Инструменты сайта


windows:portable_tools:python:start

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слеваПредыдущая версия
Следующая версия
Предыдущая версия
windows:portable_tools:python:start [2026/05/14 12:02] windows:portable_tools:python:start [2026/05/14 12:06] (текущий)
Строка 8: Строка 8:
 ''Scripts\\'' ''Scripts\\''
  
-<code powershell>+==== Проверка на соответствие ==== 
 + 
 +<code powershell python_env_check.ps1> 
 +# ========================================= 
 +# File: python_env_check.ps1 
 +# ========================================= 
 +# DESCRIPTION: 
 +#   Portable Python Embeddable Environment Checker 
 +
 +# FEATURES: 
 +#   - Checks: 
 +#       python.exe 
 +#       pythonXY._pth 
 +#       import site 
 +#       pip 
 +#       site-packages 
 +#       writable TEMP 
 +#       PYTHONHOME 
 +#       PYTHONPATH 
 +#       user-site 
 +
 +#   - Displays: 
 +#       Python version 
 +#       Executable path 
 +#       Pip version 
 +#       Site-packages path 
 +
 +# USAGE: 
 +
 +#   powershell -ExecutionPolicy Bypass -File .\python_env_check.ps1 
 +
 +# NOTES: 
 +#   Script must be placed INSIDE portable Python root directory. 
 +
 +# EXAMPLE: 
 +
 +#   PortablePython\ 
 +#   ├── python.exe 
 +#   ├── python312._pth 
 +#   ├── python_env_check.ps1 
 +#   └── Lib\ 
 +
 +# ========================================= 
 + 
 +# ----------------------------------------- 
 +# UTF-8 Console 
 +# ----------------------------------------- 
 + 
 +[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new() 
 + 
 +# ----------------------------------------- 
 +# Helper Functions 
 +# ----------------------------------------- 
 + 
 +function Write-Status { 
 +    param ( 
 +        [string]$Status, 
 +        [string]$Message 
 +    ) 
 + 
 +    switch ($Status) { 
 +        "OK"    { $color = "Green" 
 +        "WARN"  { $color = "Yellow"
 +        "ERROR" { $color = "Red"    } 
 +        default { $color = "White" 
 +    } 
 + 
 +    Write-Host ("[{0}]" -f $Status).PadRight(10) -ForegroundColor $color -NoNewline 
 +    Write-Host $Message 
 +
 + 
 +function Test-WritableDirectory { 
 +    param ( 
 +        [string]$Path 
 +    ) 
 + 
 +    try { 
 +        $testFile = Join-Path $Path "write_test.tmp" 
 + 
 +        "TEST" | Out-File -FilePath $testFile -Encoding utf8 -Force 
 + 
 +        if (Test-Path $testFile) { 
 +            Remove-Item $testFile -Force -ErrorAction SilentlyContinue 
 +            return $true 
 +        } 
 + 
 +        return $false 
 +    } 
 +    catch { 
 +        return $false 
 +    } 
 +
 + 
 +# ----------------------------------------- 
 +# Root Paths 
 +# ----------------------------------------- 
 + 
 +if ($args.Count -ge 1) { 
 + 
 +    $RootDir = $args[0] 
 +
 +else { 
 + 
 +    $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path 
 + 
 +    $RootDir = Join-Path $ScriptDir "Python" 
 +
 + 
 +$RootDir = [System.IO.Path]::GetFullPath($RootDir) 
 + 
 +$PythonExe = Join-Path $RootDir "python.exe" 
 +$LauncherPath = Join-Path $RootDir "py_portable.cmd" 
 + 
 +Write-Host "" 
 +Write-Host "Python Root:" -ForegroundColor Cyan 
 +Write-Host $RootDir 
 +Write-Host "" 
 + 
 +# ----------------------------------------- 
 +# Header 
 +# ----------------------------------------- 
 + 
 +Write-Host "" 
 +Write-Host "=========================================" -ForegroundColor Cyan 
 +Write-Host " Portable Python Environment Checker"    -ForegroundColor Cyan 
 +Write-Host "=========================================" -ForegroundColor Cyan 
 +Write-Host "" 
 + 
 +# ----------------------------------------- 
 +# Check python.exe 
 +# ----------------------------------------- 
 + 
 +if (Test-Path $PythonExe) { 
 +    Write-Status "OK" "python.exe found" 
 +
 +else { 
 +    Write-Status "ERROR" "python.exe NOT found" 
 + 
 +    Write-Host "" 
 +    Read-Host "Press Enter" 
 +    exit 
 +
 + 
 +# ----------------------------------------- 
 +# Find pythonXY._pth 
 +# ----------------------------------------- 
 + 
 +$PthFile = Get-ChildItem -Path $RootDir -Filter "python*._pth" -ErrorAction SilentlyContinue | Select-Object -First 1 
 + 
 +if ($PthFile) { 
 +    Write-Status "OK" "$($PthFile.Name) found" 
 +
 +else { 
 +    Write-Status "ERROR" "pythonXY._pth NOT found" 
 +
 + 
 +# ----------------------------------------- 
 +# Check import site 
 +# ----------------------------------------- 
 + 
 +if ($PthFile) { 
 + 
 +    $PthContent = Get-Content $PthFile.FullName -ErrorAction SilentlyContinue 
 + 
 +    $ImportSiteEnabled = $false 
 + 
 +    foreach ($line in $PthContent) { 
 + 
 +        $trim = $line.Trim() 
 + 
 +        if ($trim -eq "import site") { 
 +            $ImportSiteEnabled = $true 
 +        } 
 +    } 
 + 
 +    if ($ImportSiteEnabled) { 
 +        Write-Status "OK" "import site enabled" 
 +    } 
 +    else { 
 +        Write-Status "WARN" "import site DISABLED" 
 +    } 
 +
 + 
 +# ----------------------------------------- 
 +# Python Version 
 +# ----------------------------------------- 
 + 
 +try { 
 + 
 +    $PythonVersion = & $LauncherPath --version 2>&
 + 
 +    Write-Status "OK" "$PythonVersion" 
 +
 +catch { 
 +    Write-Status "ERROR" "Cannot execute python.exe" 
 +
 + 
 +# ----------------------------------------- 
 +# Executable Path 
 +# ----------------------------------------- 
 + 
 +try { 
 + 
 +    $ExePath = & $LauncherPath -c "import sys; print(sys.executable)" 
 + 
 +    Write-Status "OK" "Executable: $ExePath" 
 +
 +catch { 
 +    Write-Status "ERROR" "Cannot get executable path" 
 +
 + 
 +# ----------------------------------------- 
 +# Check pip 
 +# ----------------------------------------- 
 + 
 +try { 
 + 
 +    $PipVersion = & $LauncherPath -m pip --version 2>&
 + 
 +    if ($LASTEXITCODE -eq 0) { 
 +        Write-Status "OK" "pip available" 
 +        Write-Host "         $PipVersion" 
 +    } 
 +    else { 
 +        Write-Status "WARN" "pip NOT available" 
 +    } 
 +
 +catch { 
 +    Write-Status "WARN" "pip check failed" 
 +
 + 
 +# ----------------------------------------- 
 +# Check site-packages 
 +# ----------------------------------------- 
 + 
 +try { 
 + 
 +    $SitePackages = & $LauncherPath -c "import site; print(site.getsitepackages()[0])" 2>&
 + 
 +    if ($LASTEXITCODE -eq 0) { 
 + 
 +        Write-Status "OK" "site-packages available" 
 +        Write-Host "         $SitePackages" 
 + 
 +        if (Test-Path $SitePackages) { 
 +            Write-Status "OK" "site-packages path exists" 
 +        } 
 +        else { 
 +            Write-Status "WARN" "site-packages path missing" 
 +        } 
 +    } 
 +    else { 
 +        Write-Status "WARN" "site-packages unavailable" 
 +    } 
 +
 +catch { 
 +    Write-Status "WARN" "Cannot check site-packages" 
 +
 + 
 +# ----------------------------------------- 
 +# Check user-site 
 +# ----------------------------------------- 
 + 
 +try { 
 + 
 +    $UserSite = & $LauncherPath -c "import site; print(site.ENABLE_USER_SITE)" 
 + 
 +    if ($UserSite -eq "False") { 
 +        Write-Status "OK" "user-site disabled" 
 +    } 
 +    else { 
 +        Write-Status "WARN" "user-site ENABLED" 
 +    } 
 +
 +catch { 
 +    Write-Status "WARN" "Cannot check user-site" 
 +
 + 
 +# ----------------------------------------- 
 +# Check User Site Path 
 +# ----------------------------------------- 
 + 
 +try { 
 + 
 +    $UserSitePath = & $LauncherPath -c "import site; print(site.getusersitepackages())" 
 + 
 +    if ($UserSite -eq "False") { 
 + 
 +        Write-Status "OK" "User site isolated" 
 +        Write-Host "         $UserSitePath" 
 +    } 
 +    else { 
 + 
 +        Write-Status "WARN" "User site ENABLED" 
 +        Write-Host "         $UserSitePath" 
 +    } 
 +
 +catch { 
 + 
 +    Write-Status "WARN" "Cannot check user-site path" 
 +
 + 
 + 
 +# ----------------------------------------- 
 +# Check PYTHONHOME 
 +# ----------------------------------------- 
 + 
 +if ($env:PYTHONHOME) { 
 +    Write-Status "WARN" "PYTHONHOME detected: $($env:PYTHONHOME)" 
 +
 +else { 
 +    Write-Status "OK" "PYTHONHOME not set" 
 +
 + 
 +# ----------------------------------------- 
 +# Check PYTHONPATH 
 +# ----------------------------------------- 
 + 
 +if ($env:PYTHONPATH) { 
 +    Write-Status "WARN" "PYTHONPATH detected: $($env:PYTHONPATH)" 
 +
 +else { 
 +    Write-Status "OK" "PYTHONPATH not set" 
 +
 + 
 +# ----------------------------------------- 
 +# Check TEMP Write Access 
 +# ----------------------------------------- 
 + 
 +$TempDir = Join-Path $RootDir "TEMP" 
 + 
 +if (-not (Test-Path $TempDir)) { 
 + 
 +    try { 
 +        New-Item -ItemType Directory -Path $TempDir -Force | Out-Null 
 +    } 
 +    catch {} 
 +
 + 
 +if (Test-WritableDirectory -Path $TempDir) { 
 +    Write-Status "OK" "TEMP writable" 
 +
 +else { 
 +    Write-Status "WARN" "TEMP NOT writable" 
 +
 + 
 +# ----------------------------------------- 
 +# Check Local site-packages Folder 
 +# ----------------------------------------- 
 + 
 +$LocalSitePackages = Join-Path $RootDir "Lib\site-packages" 
 + 
 +if (Test-Path $LocalSitePackages) { 
 +    Write-Status "OK" "Local site-packages exists" 
 +
 +else { 
 +    Write-Status "WARN" "Local site-packages missing" 
 +
 + 
 + 
 +# ----------------------------------------- 
 +# Check sys.path 
 +# ----------------------------------------- 
 + 
 +try { 
 + 
 +    Write-Host "" 
 +    Write-Host "sys.path:" -ForegroundColor Cyan 
 + 
 +    & $LauncherPath -c "import sys; [print(x) for x in sys.path]" 
 +
 +catch { 
 + 
 +    Write-Status "WARN" "Cannot display sys.path" 
 +
 + 
 + 
 + 
 + 
 +# ----------------------------------------- 
 +# Footer 
 +# ----------------------------------------- 
 + 
 +Write-Host "" 
 +Write-Host "=========================================" -ForegroundColor Cyan 
 +Write-Host " Check Complete"                         -ForegroundColor Cyan 
 +Write-Host "=========================================" -ForegroundColor Cyan 
 +Write-Host "" 
 + 
 +Read-Host "Press Enter" 
 +</code> 
 + 
 +==== Исправление ==== 
 + 
 +<code powershell python_env_repair.ps1>
 # ========================================= # =========================================
 # File: python_env_repair.ps1 # File: python_env_repair.ps1
windows/portable_tools/python/start.1778749358.txt.gz · Последнее изменение:

Если не указано иное, содержимое этой вики предоставляется на условиях следующей лицензии: CC Attribution 4.0 International
CC Attribution 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki