Windows版ChatGPT报错:

ChatGPT failed to start
Unable to locate the Codex CLI binary

解决方法:

新建fixgpt.ps1,把修复脚本贴进去,然后用PowerShell管理员权限运行。

它会自动寻找codex.exe,设置CODEX_CLI_PATH,再把ChatGPT重启。

不用卸载,不用手动翻安装目录。

[CmdletBinding()]
param(
    [switch]$NoRestart
)

$ErrorActionPreference = 'Stop'

function Write-Status {
    param([string]$Message)
    Write-Host "[Codex Repair] $Message"
}

try {
    $package = Get-AppxPackage -Name 'OpenAI.Codex' |
        Sort-Object Version -Descending |
        Select-Object -First 1

    if ($null -eq $package) {
        throw 'OpenAI.Codex desktop package was not found. Install it first.'
    }

    $candidates = @(
        (Join-Path $package.InstallLocation 'app\resources\codex.exe'),
        (Join-Path $package.InstallLocation 'app\bin\codex.exe'),
        (Join-Path $package.InstallLocation 'app\Codex.exe')
    )
    $cliPath = $candidates | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1

    if ($null -eq $cliPath) {
        throw "Codex CLI was not found. Checked: $($candidates -join '; ')"
    }

    [Environment]::SetEnvironmentVariable('CODEX_CLI_PATH', $cliPath, 'User')
    Write-Status "Set user environment variable CODEX_CLI_PATH: $cliPath"

    if ($NoRestart) {
        Write-Status 'Repair complete. Fully close and reopen the Codex desktop app.'
        exit 0
    }

    Get-Process -Name 'ChatGPT' -ErrorAction SilentlyContinue | Stop-Process -Force
    Start-Sleep -Seconds 2

    $appId = "$($package.PackageFamilyName)!App"
    Start-Process -FilePath 'explorer.exe' -ArgumentList "shell:AppsFolder\$appId"
    Write-Status 'Repair complete. The Codex desktop app was restarted.'
}
catch {
    Write-Error "Codex desktop repair failed: $($_.Exception.Message)"
    exit 1
}

原文地址: https://www.cveoy.top/t/topic/qHv2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录