欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PowerShell 實現(xiàn) conda 懶加載的問題及解決方案

 更新時間:2025年05月17日 15:07:16   作者:zhang-hui  
本文展示了如何實現(xiàn)conda的懶加載,默認(rèn)不加載conda環(huán)境,只有在用戶執(zhí)行conda命令時才加載,本文給大家分享解決方案,感興趣的朋友一起看看吧

問題

執(zhí)行命令conda init powershell會在 profile.ps1中添加conda初始化的命令。
即使用戶不需要用到conda,也會初始化conda環(huán)境,拖慢PowerShell的啟動速度。

解決方案

本文展示了如何實現(xiàn)conda的懶加載,默認(rèn)不加載conda環(huán)境,只有在用戶執(zhí)行conda命令時才加載。

(1) Path環(huán)境變量添加conda路徑

  • 添加conda3的本地路徑:D:\code\miniconda3
  • 添加conda3的腳本路徑:D:\code\miniconda3\Scripts

(2) 注銷conda初始化命令

  • 進(jìn)入文件夾:C:\Users<user_name>\Documents\WindowsPowerShell
  • 編輯profile.ps1文件,注釋或刪除conda初始化代碼
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
# If (Test-Path "D:\code\miniconda3\Scripts\conda.exe") {
#    (& "D:\code\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
# }
#endregion

(3) 封裝conda命令,實現(xiàn)懶加載

  • 進(jìn)入文件夾:C:\Users<user_name>\Documents\WindowsPowerShell
  • 編輯Microsoft.PowerShell_profile.ps1文件,添加代碼。
function Load-Conda {
    If (Test-Path "D:\code\miniconda3\Scripts\conda.exe") {
        (& "D:\code\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | ?{$_} | Invoke-Expression
    }
    conda @args
}
Set-Alias conda Load-Conda

到此這篇關(guān)于PowerShell 實現(xiàn) conda 懶加載的文章就介紹到這了,更多相關(guān)PowerShell 實現(xiàn) conda 懶加載內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論