如何在Visual Studio Code中激活一个虚拟环境?

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

How to activate a venv in VSC?

问题

我在VSC中打开了一个Python脚本。我选择了一个名为venv(Python 3.10.0)的环境作为内核。在终端中,我看到了以下这行:

PS C:\Users\person123\Desktop\Project\venv>

我认为我的venv没有被激活。我正确吗?如何激活它?我看到的指令似乎没有起作用(例如这个venv\Scripts\activate)。感谢您的帮助。

英文:

I have a Python script open in VSC. I have a venv (Python 3.10.0) selected as the Kernel. In terminal I have the following line:

PS C:\Users\person123\Desktop\Project\venv>

I think my venv is not activated. Am I correct and how to activate it? The instruction tricks I've seen (for example this venv\Scripts\activate) don't activate this venv. Thanks for your assistance.

答案1

得分: 1

通过快捷键 "Ctrl+Shift+P" 选择解释器,然后在 vscode 中输入 "Python: Select Interpreter",当您运行 Python 脚本时,环境将自动激活。

英文:

Selecting an interpreter by shortcuts "Ctrl+Shift+P" and type "Python: Select Interpreter" in vscode, environment will be automatically activated when you run the python script.

答案2

得分: 0

看起来你正在使用PowerShell。要激活你的虚拟环境,你应该运行activate.ps1脚本:

.\venv\Scripts\activate.ps1

然后要检查它是否正确激活,检查你的Python可执行文件的路径:

(Get-Command python).Path

它应该指向你的Python虚拟环境。

英文:

Looks like you are using powershell. To activate your venv, you should run the activate.ps1 script:

.\venv\Scripts\activate.ps1

And to check if it is properly activated, check the path of your python executable:

(Get-Command python).Path

It should point to your python venv.

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

发表评论

匿名网友

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

确定