python - 如何使用命令行在 Visual Studio Code 中为 python 设置虚拟环境
问题描述
我是一个非常新的程序员,现在我已经学习了 Python 的基础知识,正在尝试学习 Flask。我正在关注本教程https://www.youtube.com/watch?v=Z1RJmh_OqeA&t=355s ...我被困在 5:46。
本教程以及其他几个网站上的文档解释了键入以下命令:\env\Scripts\activate.bat
for Windows,他们建议使用:source env/bin/activate
for 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
运行这些命令后,本教程要求我运行我遇到问题的命令。
我有什么选择来解决这个问题?
解决方案
您可能没有设置路径变量,因此系统找不到 Scripts 文件夹。在 Windows 上的典型 Python 安装中(您似乎正在使用它),Python 安装在 Program Files 的 C 驱动器下,并且该目录内是 Scripts 目录,它就是所在的位置virtualenv.exe
。
所以你需要打开控制面板,进入系统,点击高级系统设置,点击环境变量,然后在用户变量下突出显示路径,点击编辑,看看脚本的路径是否存在;它会是这样
C:\Program Files\Python37\Scripts
的:如果它不存在,您需要单击“新建”并输入它。
推荐阅读
- mongodb - 如何将csv文件导入mongoDB,其中mongo字段具有数组字段
- python - 当工人被杀时,芹菜中重新排队任务的默认等待时间是多少?
- excel - 如何使用文本文件中的文本填充 ComboBox 和 TextBox
- python - 通过解决 procrustes 问题的线性投影矩阵
- opencv - 基于分割的对象跟踪
- reactjs - 无法在 JSX 中导入视频组件
- python - 如何在python中运行“for”循环以获得有限结果
- sql-server - 在 SQL Server 2016(Power BI 服务器)上从 SSRS 将大文件导出到 Excel 时出错
- javascript - 在移动浏览器中打开时是否可以从反应应用程序重定向到已安装的颤振应用程序页面
- ubuntu - 无法解决letsencrypt错误,原因未知