PowerShell 實現(xiàn) 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)文章
自定義PowerShell控制臺提示符風(fēng)格的方法
這篇文章主要介紹了自定義PowerShell控制臺提示符風(fēng)格的方法,需要的朋友可以參考下2014-04-04PowerShell中簡單的自定義函數(shù)和調(diào)用函數(shù)例子
這篇文章主要介紹了PowerShell中簡單的自定義函數(shù)和調(diào)用函數(shù)例子,非常簡單的一個小例子,需要的朋友可以參考下2014-08-08Powershell Profiles配置文件的存放位置介紹
這篇文章主要介紹了Powershell Profiles配置文件的存放位置介紹,Profiles文件存放的位置不同,它的作用域也會不同,需要的朋友可以參考下2014-08-08PowerShell啟用winrm失?。壕芙^訪問 0x80070005 -2147024891
這篇文章主要介紹了PowerShell啟用winrm失敗:拒絕訪問 0x80070005 -2147024891,本文給出了詳細(xì)的排查步驟和解決方法,需要的朋友可以參考下2015-06-06windows Powershell 快速編輯模式和標(biāo)準(zhǔn)模式
powershell控制臺有兩種模式,一個是快速編輯模式,一個是標(biāo)準(zhǔn)模式。2014-08-08Windows Powershell ForEach-Object 循環(huán)
Powershell管道就像流水線,對于數(shù)據(jù)的處理是一個環(huán)節(jié)接著一個環(huán)節(jié),如果你想在某一環(huán)節(jié)對流進(jìn)來的數(shù)據(jù)逐個細(xì)致化的處理,可是使用ForEach-Object,$_ 代表當(dāng)前的數(shù)據(jù)。2014-10-10