conda在powershell7.5执行出现问题
问题描述
执行命令结果如下,不能达到预期
conda
usage: conda-script.py [-h] [-v] [--no-plugins] [-V] COMMAND ...
conda-script.py: error: argument COMMAND: invalid choice: '' (choose from 'activate', 'clean', 'commands', 'compare', 'config', 'create', 'deactivate', 'env', 'export', 'info', 'init', 'install', 'list', 'notices', 'package', 'build', 'content-trust', 'convert', 'debug', 'develop', 'doctor', 'index', 'inspect', 'metapackage', 'render', 'repoquery', 'skeleton', 'pack', 'repo', 'token', 'server', 'remove', 'uninstall', 'rename', 'run', 'search', 'update', 'upgrade')
原因
这是原文记录的 PowerShell 7.5 与旧版 Conda 集成脚本兼容问题。不要只凭相似报错就降级整个 PowerShell;先记录实际的 PowerShell 与 Conda 版本,确认是否仍属于同一个问题。
解决方法
1. 从能正常工作的 Conda 终端更新
如果 PowerShell 中的 conda 函数已不能正常调用,可先打开安装器提供的 Anaconda Prompt / Miniforge Prompt,在那里查看并更新:
conda --version
conda update -n base conda
conda init powershell
更新前记录原版本并阅读求解器显示的变更。25.1.1 是原文补充的修复版本记录,不应写成所有环境都要长期锁定的版本;已有更新版本时不必反向降级。
2. 重开 PowerShell 验证
关闭旧终端,重新启动 PowerShell,再执行:
$PSVersionTable.PSVersion
Get-Command conda -All
conda --version
conda activate base
python -c "import sys; print(sys.executable)"
检查最终解释器是否属于预期的 base 环境。若仍有问题,再检查 $PROFILE 及其 Conda 初始化区块,修改前备份实际的配置文件。Windows PowerShell、PowerShell 7 和不同宿主的配置文件路径可能不同,不要把某个固定目录当作全部配置。
3. 无法更新时的临时选择
原文曾通过 PowerShell 7.4.7 暂时避开问题,保留对应历史版本链接。优先使用能正常工作的 Conda Prompt 完成操作;如确需另一版本 PowerShell,先确认兼容性并保留原配置,无需先卸载现有终端或删除整个配置目录。
参考
标题: PowerShell 7.5.0 中的 Conda 环境激活问题 ·问题 #24942 ·PowerShell/PowerShell
Conda does not run as expected on PowerShell 7.5.0 · Issue #24869 · PowerShell/PowerShell
评论将在接近此处时加载,也可点击立即加载。