


































处理方案收集自网络,原因是在执行 conda init 命令时
自动向 PowerShell 初始化文件中加了一段初始化 conda 环境的命令
在 PowerShell 环境中输入以下命令查看初始化文件所在位置:
$PROFILE
1、删除或注释该文件中以下代码
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
#If (Test-Path "X:\your\path\miniforge3\Scripts\conda.exe") {
# (& "X:\your\path\miniforge3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
#}
#endregion
2、将文件中原代码封装为方法,在使用 conda 命令前单独执行初始化(方法名自定义,记得住就行)
#region conda initialize
function initconda() {
# !! Contents within this block are managed by 'conda init' !!
If (Test-Path "X:\your\path\miniforge3\Scripts\conda.exe") {
(& "X:\your\path\miniforge3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
}
}
#endregion
3、将原代码包装一层延迟启动,首次使用 conda 命令时会有所延迟
#region conda initialize
# 简单的 Conda 延迟加载
function Invoke-CondaInit {
if (-not $script:CondaAlreadyInitialized) {
Write-Host "Init Conda..." -ForegroundColor Yellow
# !! Contents within this block are managed by 'conda init' !!
If (Test-Path "X:\your\path\miniforge3\Scripts\conda.exe") {
(& "X:\your\path\miniforge3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
}
$script:CondaAlreadyInitialized = $true
}
}
# 只有在使用 conda 相关命令时才初始化
Set-Alias -Name conda -Value conda-wrapper
function conda-wrapper {
Invoke-CondaInit
conda @args
}
#endregion
参考来源:
https://v1hz.blog/post/e0be4916.html
https://alayedong.cn/posts/2025/fixing-slow-powershell-startup-caused-by-conda/#%E5%AE%9E%E7%8E%B0-conda-%E5%BB%B6%E8%BF%9F%E5%8A%A0%E8%BD%BD
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。