如何更改 Visual Studio Code 中默认的虚拟环境命令?

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

How can I change the default virtual environment command in Visual Studio Code?

问题

我在项目文件夹中使用命令面板创建了一个虚拟环境:Python: Create Environment: .venv。所以每当我在那个文件夹中打开vs code时,它会尝试使用 .venv/Scripts/Activate.ps1 文件启动环境,但由于对PowerShell禁用了运行脚本,这会失败。所以我想将默认终端切换到命令提示符,并默认执行 .venv/Scripts/Activate.bat。

我成功将默认终端切换到cmd,但vs code仍然尝试运行 .venv/Scripts/Activate.ps1,而不是 .venv/Scripts/Activate.bat。我如何将默认命令从

& <file-path>/.venv/Scripts/Activate.ps1

改为

<file-path>/.venv/Scripts/Activate.bat

编辑:
所以我想更清楚地说明这个问题...

我没有问题手动再次运行该命令或创建一个新终端,但这个错误真的让我很困扰。希望这能帮到您理清问题。

英文:

I have setup a virtual environment in my project folder using Command Palette: Python: Create Environment: .venv
So whenever I open vs code in that folder it attempts to start the environment using .venv/Scripts/Activate.ps1 file which fails as running scripts is disabled for Powershell. So I want to switch to command prompt as default terminal and execute .venv/Scripts/Activate.bat by default instead.

I am able to switch default terminal to cmd but vs code still tries to run the .venv/Scripts/Activate.ps1 instead of .venv/Scripts/Activate.bat. How do I switch this default command from

& <file-path>/.venv/Scripts/Activate.ps1

to

<file-path>/.venv/Scripts/Activate.bat 

Edit:
So I want to be more clear about the issue...

I have no problem running the command again manually or creating a new terminal, but this error really bugs me. Hope this helps clear the problem.

答案1

得分: 0

抱歉,我无法执行代码或直接返回代码的翻译部分。

英文:

When you choose a virtual environment interpreter, vscode will automatically activate the environment every time you build a new terminal. This is controlled by the following settings, and the default value is true.

	"python.terminal.activateEnvironment": true,

如何更改 Visual Studio Code 中默认的虚拟环境命令?

The shell command that activates the virtual environment is based on your terminal automatic change:

  • PowerShell is & e:/workspace/py12/.venv/Scripts/Activate.ps1

    如何更改 Visual Studio Code 中默认的虚拟环境命令?

  • CMD is e:/workspace/py12/.venv/Scripts/activate.bat

    如何更改 Visual Studio Code 中默认的虚拟环境命令?

As for you every time you build a new terminal, you will create a new PowerShell or CMD, which is controlled by the following settings

	"terminal.integrated.defaultProfile.windows": "PowerShell",

如何更改 Visual Studio Code 中默认的虚拟环境命令?

huangapple
  • 本文由 发表于 2023年2月18日 21:51:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75493787.html
匿名

发表评论

匿名网友

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

确定