解决关于 ChatGPT 登入打开报错的问题 ChatGPT failed to start. Unable to locate the Codex CLI binary. Set CODEX_CLI PATH or ensure the Electron resources include bin/codex.

瑶瑶发大财 2026-08-26 19:40 1

创建 fixgpt.ps1 把下面的复制进去 - 通过 powershell 管理员运行即可


[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
}
最新回复 (1)
  • 噜噜 08-27 07:16
    1

    神医呀,感谢佬友的分享!活了哈哈哈哈

* 帖子来源Linux.do
返回