When Windows uses codex to execute scripts, pop-up boxes always pop up that conda.exe cannot be opened

Resolved 💬 5 comments Opened Nov 23, 2025 by dzy888 Closed Mar 29, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

When Windows uses codex to execute scripts, pop-up boxes always pop up that conda.exe cannot be opened

What subscription do you have?

When Windows uses codex to execute scripts, pop-up boxes always pop up that conda.exe cannot be opened

Which model were you using?

When Windows uses codex to execute scripts, pop-up boxes always pop up that conda.exe cannot be opened

What platform is your computer?

_No response_

What issue are you seeing?

When Windows uses codex to execute scripts, pop-up boxes always pop up that conda.exe cannot be opened

What steps can reproduce the bug?

When Windows uses codex to execute scripts, pop-up boxes always pop up that conda.exe cannot be opened

What is the expected behavior?

_No response_

Additional information

_No response_

View original on GitHub ↗

5 Comments

alanchancl · 9 months ago

这是一个非常典型的 环境冲突(DLL 初始化失败) 问题。

核心原因分析:

你遇到的错误 0xc0000142(DLL Initialization Failed)结合 conda.exe 报错,说明问题的根源在于:

当你的 Codex 插件(或 IDE)试图调用 PowerShell 执行命令时,PowerShell 会默认加载你的个人配置文件(Profile)。而在你的配置文件中,包含了 Conda 的自动初始化代码。

这就形成了一个死循环:

  1. Codex 启动 PowerShell。
  2. PowerShell 启动时自动运行 $PROFILE 脚本。
  3. 脚本里调用了 conda.exe 来激活环境。
  4. 在这个非交互式(Non-interactive)或受限的 shell 环境中,conda.exe 因为路径、编码或 DLL 冲突无法正常启动,直接崩溃,弹出了这个 0xc0000142 错误窗口。

-----

解决方案

要彻底解决这个问题,你需要阻止 PowerShell 在启动时自动加载 Conda。请按以下顺序尝试:

方案一:手动修改 PowerShell 配置文件(最推荐,治标治本)

既然 Conda 已经坏到无法运行命令来关闭自己,我们需要手动去改配置文件。

  1. 打开一个新的 PowerShell 窗口(如果你还能打开的话)。
  2. 输入以下命令打开配置文件:

``powershell
notepad $PROFILE
`
*注意:如果报错说找不到文件,说明你可能没有配置文件,或者路径不对,可以尝试检查
C:\Users\你的用户名\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1`*

  1. 在打开的记事本中,找到类似下面的一段代码(这是 Conda 的初始化代码):

``powershell
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "D:\Anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
``

  1. 操作: 将这一整段代码前面全部加上 # 号注释掉,或者直接 删除 这一段。
  2. 保存并关闭记事本。
  3. 重启你的编辑器/IDE,再次运行 Codex,问题应该就会消失。

-----

如果Microsoft.PowerShell_profile.ps1没有相关代码的配置文件里没有 Conda 的代码,但启动时依然报错 conda.exe,这说明Conda 的启动命令藏在另一个 PowerShell 配置文件中。

PowerShell 启动时会按顺序加载多达 4 个不同的配置文件。你刚才打开的可能只是其中一个(通常是当前用户的当前主机配置),而 Conda 可能把代码写在了\\“所有主机”或“所有用户”\\的配置里。

请按以下步骤找到“真凶”:

1\. 找出所有配置文件的路径

请在 PowerShell 中运行下面这行命令:

$PROFILE | Select-Object *

运行后,你会看到类似这样的输出(有 4 个路径):

  • AllUsersAllHosts: (所有用户,所有终端)
  • AllUsersCurrentHost: (所有用户,当前终端)
  • CurrentUserAllHosts: (当前用户,所有终端)
  • CurrentUserCurrentHost: (当前用户,当前终端 —— 你刚才改的可能就是这个)
2\. 检查其他存在的配置文件

请检查上述命令输出的路径。如果路径对应的文件存在,请用记事本打开它们。

重点检查 CurrentUserAllHosts 对应的路径(通常是 Documents\WindowsPowerShell\profile.ps1,注意文件名没有 Microsoft. 前缀)。

一旦在某个文件里发现了下面这段代码,删掉它或注释掉它:

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "你的conda路径\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

-----

liguochuan00 · 9 months ago

nice,你解决了我的大问题,非常感谢

hiajoo · 9 months ago

@alanchancl's suggestion is great but it did not work on my PC.

I fixed it by implementing lazy loading. Here are the steps:

  1. Open your PowerShell profile:
notepad $PROFILE

Delete the original initialization block:


#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "D:\Anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

Paste this lazy loading function instead:


function conda {
    # You can change the text inside quotes to English if you prefer
    Write-Host "Waking up Conda..." -ForegroundColor DarkGray

    # Ensure this path points to your actual conda.exe
    $EnvBlock = (& "D:\conda\Scripts\conda.exe" "shell.powershell" "hook") | Out-String
    Invoke-Expression $EnvBlock

    Remove-Item Function:\conda

    Invoke-Expression "conda $args"
}

I don't know exactly why it works, but I haven't encountered any bugs so far.

wesleywang77 · 8 months ago

@alanchancl 的方法确实管用,现在不会出现conda.exe的报错了,但是当codex试图执行python命令时,还是会出现python.exe的0xc0000142报错,如何解决?

etraut-openai contributor · 5 months ago

This bug report hasn't received any upvotes or additional posts in three months. Closing.