英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论