当前位置: 首页 > news >正文

解决scoop安装的anaconda无法在商店版powershell使用的问题

1) 不依赖 profile,先在当前会话“临时启用” conda

$CondaRoot = 'D:\Scoop\apps\anaconda3\current\App'
$env:PATH = "$CondaRoot\condabin;$CondaRoot\Scripts;$CondaRoot;$CondaRoot\Library\bin;$env:PATH"# 关键点:**用点号 dot-source** 加载官方 hook(不要用 &)
. "$CondaRoot\shell\condabin\conda-hook.ps1"# 立即验证
Get-Command conda
conda -V
conda info
  • 如果这一步就能成功显示版本/信息,说明问题只是“启动时没正确加载 hook”。继续第 2 步把它写入 profile。
  • 如果依旧不行,先看 Get-Command conda 输出了什么(是否有 Function conda);如果没有,往下做第 3 步“强力最小函数”。

2) 用“官方 hook”固化到 profile(替换写入)

把 hook 和 PATH 固化到 PowerShell 7 专属 profile当前用户-所有主机的 profile;我们用覆盖写入,避免之前追加了很多次导致混乱。

$CondaRoot = 'D:\Scoop\apps\anaconda3\current\App'# 确保目录 & 文件存在
$files = @($PROFILE, $PROFILE.CurrentUserAllHosts)
foreach ($f in $files) {$dir = Split-Path -Parent $fif (!(Test-Path $dir)) { New-Item -ItemType Directory -Path $dir | Out-Null }
}# 统一写入内容(覆盖 Set-Content)
$content = @"
# ===== Conda bootstrap (Store pwsh 7) =====
`$CondaRoot = "$CondaRoot"
`$env:PATH = "$CondaRoot\condabin;$CondaRoot\Scripts;$CondaRoot;$CondaRoot\Library\bin;`$env:PATH"
. "$CondaRoot\shell\condabin\conda-hook.ps1"
# 可选:启动即激活 base,取消下一行注释
# conda activate base
# ===== End =====
"@Set-Content -Path $PROFILE -Value $content -Encoding UTF8
Set-Content -Path $PROFILE.CurrentUserAllHosts -Value $content -Encoding UTF8# 执行策略(仅当前用户)
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force# 立刻加载并验证
. $PROFILE
Get-Command conda
conda -V

重点:conda-hook.ps1 要用「点号 .」加载,否则不会把 conda 函数注入当前会话。这是很多人卡住的地方。


3) 如果官方 hook 仍然无效,用“最小函数”兜底

(极少见,但商店版 pwsh 在某些环境里 hook 不生效时,这招最稳。)

$CondaRoot = 'D:\Scoop\apps\anaconda3\current\App'
$min = @"
# ===== Conda minimal fallback =====
`$CondaRoot = "$CondaRoot"
`$env:PATH = "$CondaRoot\condabin;$CondaRoot\Scripts;$CondaRoot;$CondaRoot\Library\bin;`$env:PATH"
function conda { & "$CondaRoot\condabin\conda.bat" @Args }
# conda activate base
# ===== End =====
"@
Set-Content -Path $PROFILE -Value $min -Encoding UTF8
. $PROFILE
conda -V

4) 两个快速自检

# A) 确认不是以 -NoProfile 启动
$PSCommandPath  # 通常为空;若你用的是带 -NoProfile 的快捷方式,请改回默认# B) 看看当前会话里 conda 的解析
Get-Command conda -All
$env:PATH -split ';' | ? { $_ -match 'anaconda3|conda|Scoop' }

仍不行?三件事再确认

  1. 你确实在 PowerShell 7(pwsh) 中做这些(窗口标题通常是 PowerShell 7.x$PSVersionTable.PSVersion 主版本应为 7);
  2. $CondaRoot 写的是 ...\anaconda3\current\App(你前面的输出已表明文件都在那里);
  3. 没用到公司/学校的限制策略:Get-ExecutionPolicy -ListCurrentUser 至少是 RemoteSignedBypass

照着上面 1→2→3 的顺序走,通常在第 1 或第 2 步就能恢复 conda

http://www.rkmt.cn/news/19339.html

相关文章:

  • 2025校平机厂家最新权威推荐榜:精准矫平与高效生产首选
  • 2025年苹果仓民宿最新权威推荐榜:工业遗存与人文情怀完美融
  • 鲜花 10.12
  • 数组01
  • 排除通过IP访问MySQL时出现的连接错误问题
  • 很早就想注册博客园了
  • AI代理从概念验证到生产部署全流程
  • CPU中的加法运算与减法运算
  • 笔记(C++篇)—— Day 12 - 详解
  • C++ - 从字符串中提取一个数的若干种写法
  • 深入解析:深入理解Kafka的复制协议与可靠性保证
  • 一键解决MetaHuman播放动画时头部穿模问题
  • 缓存一致性验证秘笈
  • 元推理:汉字的发音,同音也是某种同构?
  • 题解:qoj7759 Permutation Counting 2
  • EtherCAT芯片没有倍福授权的风险
  • 为何是「对话式」智能体?因为人类本能丨对话式智能体专场,Convo AIRTE2025
  • 2014-2024高考真题考点分布详细分析(另附完整高考真题下载) - 详解
  • CentOS 7 安装 bzip2-libs-1.0.6-13.el7.x86_64.rpm 的详细步骤
  • 单片机学习日记 - 详解
  • 金铲铲明星学生2触发条件
  • CSharp: Aspose.Cells 8.3.0 web excel Viewer
  • 【springboot的分页功能TableDataInfo,有时候需要艰难的分页实现,怎么办呢?】
  • PHP 15 个高效开发的小技巧
  • AI元人文构想研究:人类拥抱AI的文明新范式
  • 文本派 - 停服公告 2025
  • Arista vEOS 4.35.0F 发布 - 虚拟化的数据中心和云网络可扩展操作系统
  • 深入解析:Spring依赖注入方式
  • Arista EOS 4.35.0F 发布 - 适用于下一代数据中心和云网络的可扩展操作系统
  • CSharp: itextsharp5 imge converter pdf