vscode python venv – activate.ps1 被用来替代 activate.bat

huangapple go评论84阅读模式
英文:

vscode python venv - activate.ps1 is used instead of activate.bat

问题

在 vscode 用户设置中,"terminal.integrated.defaultProfile.windows" 已声明为 "Command Prompt"。
我已经在 vscode 中创建了一个 Python 虚拟环境 (venv)。
当在虚拟环境内部打开 vscode 时,会打开一个集成的 cmd 终端。自动执行命令 "& <正确的虚拟环境路径>/.venv/Scripts/Activate.ps1" 导致错误 "&" 无法在此处语法处理。

我本来期待,由于全局 cmd-shell 设置,自动执行的脚本应该是 "<正确的虚拟环境路径>/.venv/Scripts/activate.bat"。在集成终端中手动执行此脚本会正确激活环境。
我已尝试查找关于终端配置文件的文档,但未能使初始集成终端执行正确的脚本。
请问是否有人可以给我提供必要的配置变量提示。

英文:

In the vscode user settings "terminal.integrated.defaultProfile.windows": "Command Prompt" is declared.
I have created a python virtual env (venv) from within vscode.
When opening vscode from within the venv, an integrated cmd-terminal is opened. The command "& <correct path to venv>/.venv/Scripts/Activate.ps1" is automatically executed leading to the error ""&" kann syntaktisch an dieser Stelle nicht verarbeitet werden."

I would have awaited, that, due to the global cmd-shell setting, the automatically executed script would be "<correct path to venv>/.venv/Scripts/activate.bat". Executing this script manually in the integrated terminal leads to the correct activation of the environment.
I have tried what I have found in the documentation concerning terminal profiles but didn't manage to get the initial integrated terminal to execute the right script.
Could someone please give me a hint to the necessary configuration variable(s).

答案1

得分: 1

如果选择虚拟环境解释器,vscode将在构建新终端时自动激活该环境。

"python.terminal.activateEnvironment": true,

您的问题可能是由终端缓存引起的,添加以下设置以关闭记录终端会话历史记录。

"terminal.integrated.enablePersistentSessions": false,
英文:

If you choose a virtual environment interpreter, vscode will automatically activate the environment when you build a new terminal.

	&quot;python.terminal.activateEnvironment&quot;: true,

Your problem may be caused by the terminal cache, add the following setting to turn off recording terminal session history

    &quot;terminal.integrated.enablePersistentSessions&quot;: false,

huangapple
  • 本文由 发表于 2023年7月31日 20:46:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76803779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定