VSCode中使用conda activate 虚拟环境,没报错,但没进入环境
VSCode中使用conda activate 虚拟环境,没报错,但没进入环境
Windows 原生 PowerShell 默认禁止运行脚本,且未加载 Conda 配置,需两步操作:
- 允许 PowerShell 运行脚本(仅需执行一次):
- 以「管理员身份」打开 Windows 自带的「PowerShell」(不是 VS Code 中的终端);
- 在 「PowerShell」中执行下面命令:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
(作用:允许当前用户运行本地信任的脚本,不影响系统安全)
- 让 Conda 配置 PowerShell:
- 回到 VS Code,打开「PowerShell」终端(终端下拉菜单→选择「PowerShell」);
*执行 Conda 初始化命令(仅需一次):
conda init powershell
- 重启 VS Code 终端,再执行 conda activate 环境名,前缀显示 (环境名) 即成功。
【本文结束】