PowerShell进去到conda的虚拟环境base特别慢(实现conda环境懒加载)

2025年6月15日 13点热度 0人点赞 0条评论

​ 1. 打开powershell输入命令,找到powershell配置文件

$PROFILE

2. 有conda init加载导致powershell很慢的时候,配置文件如下:

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
If (Test-Path "D:\tool\Anaconda\Scripts\conda.exe") {
    (& "path\to\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
}
#endregion

实现conda环境懒加载,只需把内容换成如下即可(此后执行conda activate 环境名时会自动初始化conda,无需预先加载)

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
function Load-Conda {
    If (Test-Path "path\to\conda.exe") {
        (& "D:\tool\Anaconda\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
    }
    conda @args
}
Set-Alias conda Load-Conda
#endregion

注意路径,保存后新开一个powershell窗口看效果。

MuWinds

这个人很懒,什么都没留下

文章评论