如何使用命令行在Visual Studio Code中为python设置虚拟环境

由于我已经学习了Python的基础知识,所以我是一个尝试学习flask的非常新的程序员。我正在按照本教程https://www.youtube.com/watch?v=Z1RJmh_OqeA&t=355s进行操作……我被困在5:46。

该教程以及其他一些网站上的文档介绍了如何键入以下命令:\env\Scripts\activate.bat(对于Windows),建议使用:source env/bin/activate(对于Mac)。

这是我得到的回报:

\env\Scripts\activate.bat : The term '\env\Scripts\activate.bat' 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.
At line:1 char:1
+ \env\Scripts\activate.bat
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\env\Scripts\activate.bat:String) [],CommandNotFoundEx  
   ception
    + FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: The command \env\Scripts\activate.bat was not found,but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command,instead type: ".\\env\Scripts\activate.bat". See "get-help about_Command_Precedence" for more details.

到目前为止,其他所有事情都进行得很顺利。这是我到目前为止所做的:

pip3 install virtualenv
virtualenv env

运行这些命令后,教程要求我运行遇到问题的命令。

我必须解决哪些选项?

nihaihaoma520 回答:如何使用命令行在Visual Studio Code中为python设置虚拟环境

您可能尚未设置路径变量,因此系统找不到Scripts文件夹。在Windows(您似乎正在使用)上的典型Python安装中,Python安装在Program Files中的C驱动器下,并且该目录内是Scripts目录,即virtualenv.exe所在的目录。

因此,您需要打开“控制面板”,转到“系统”,单击“高级系统设置”,单击“环境变量”,然后在“用户变量”下突出显示“路径”,单击“编辑”,然后查看脚本的路径是否存在;它会是这样的: C:\Program Files\Python37\Scripts 如果不存在,则需要单击“新建”并输入。

,

我认为您应该在.路径之前添加\env\...。这意味着,\env\Scripts\activate.bat可以 .\env\Scripts\activate 。 此外,您可以导航到venv\Scripts\文件夹并键入activate

本文链接:https://www.f2er.com/3140159.html

大家都在问