PowerShell 实现 conda 懒加载的问题及解决方案
问题
执行命令conda init powershell会在 profile.ps1中添加conda初始化的命令。
即使用户不需要用到conda,也会初始化conda环境,拖慢PowerShell的启动速度。
解决方案
本文展示了如何实现conda的懒加载,默认不加载conda环境,只有在用户执行conda命令时才加载。
(1) Path环境变量添加conda路径
- 添加conda3的本地路径:D:\code\miniconda3
- 添加conda3的脚本路径:D:\code\miniconda3\Scripts

(2) 注销conda初始化命令
- 进入文件夹: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命令,实现懒加载
- 进入文件夹: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到此这篇关于PowerShell 实现 conda 懒加载的文章就介绍到这了,更多相关PowerShell 实现 conda 懒加载内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Powershell Profiles配置文件的存放位置介绍
这篇文章主要介绍了Powershell Profiles配置文件的存放位置介绍,Profiles文件存放的位置不同,它的作用域也会不同,需要的朋友可以参考下2014-08-08
PowerShell启用winrm失败:拒绝访问 0x80070005 -2147024891
这篇文章主要介绍了PowerShell启用winrm失败:拒绝访问 0x80070005 -2147024891,本文给出了详细的排查步骤和解决方法,需要的朋友可以参考下2015-06-06
windows Powershell 快速编辑模式和标准模式
powershell控制台有两种模式,一个是快速编辑模式,一个是标准模式。2014-08-08
Windows Powershell ForEach-Object 循环
Powershell管道就像流水线,对于数据的处理是一个环节接着一个环节,如果你想在某一环节对流进来的数据逐个细致化的处理,可是使用ForEach-Object,$_ 代表当前的数据。2014-10-10


最新评论