首页 > 解决方案 > 当我输入 source env/bin/activate 时如何在 vs 代码编辑器中激活 virtualenv 它没有激活

问题描述

注意:我在window 10中新安装了vs代码

PS C:\Users\admin\Desktop\Kiit Project\django-ecommerce> source env/bin/activate
source : The term 'source' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
+ source env/bin/activate
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (source:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

标签: pythonvisual-studio-code

解决方案


假设您的虚拟环境的名称是env,您可以简单地进入它所在的目录(我认为是C:\Users\admin\Desktop\Kiit Project\django-ecommerce)并运行env\Scripts\activate。这应该做的工作。

但是,在 VScode 中,您可能必须编辑settings.json文件夹中存在的.vscode文件并添加以下内容:

{
    ...
    "python.pythonPath": "C:\Users\admin\Desktop\Kiit Project\django-ecommerce\env\bin\python",
    ...
}

如果您无法找到上述settings.json文件,只需按Ctrl+Shift+P并键入python Select Interpreter并按Enter。然后,您将看到一个.vscode包含您的settings.json文件的目录。

您可以编辑此文件,但是您想更改用于 VScode 实例的 Python 解释器。


推荐阅读