如何在Python中以初学者的身份安装虚拟环境
我是编程的新手,我看到很多帖子说您必须在工作Python项目时创建一个虚拟环境,以获得更好的体验,而我不能真正地将我的头缠住..... 第一个问题,为什么我需要虚拟环境? 其次,如果我不使用一个会发生什么 另外,我如何安装初学者的必要过程是什么 最后,我怎么知道我正在使用Python中的虚拟环境,例如我如何分辨差异或没有?
希望得到答案
I'm new to programming and i see lots of post saying you have to create a virtual environment for better experience while working on a python project, and i can't really wrap my head on that.....
First question, why do I need a virtual environment?
Secondly, what happens if i don't use one
Also, how do I install it what are the necessary procedures for a beginner
Lastly, how do I know I'm using a virtual environment in python, like how do I tell the difference or there is none??
Hoping to get answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为如果您有多个需要不同版本的Python或不同版本的Python软件包,则虚拟环境将防止冲突。
您可能不会遇到初学者等问题,但这是一个很好的习惯。
由于要求相互矛盾,您可能会有一个无法运行的应用程序。
运行
Python3 -M Venv my-app
将创建包含虚拟环境的目录my-app
。创建虚拟环境后,您可以使用
source my-app/bin/activate
在unix或macOS上激活它,并使用my-app/scripts/activate.bat
使用my-app/scripts/activate>在窗户上。
如果您使用的是虚拟环境,则提示将显示其名称,例如
(my-app)$
。另请参见虚拟环境和包装,来自python tutorial 。
Because a virtual environment will prevent clashes if you have several applications requiring different versions of Python, or different versions of some Python packages.
You might not run into such issues as a beginner, but it's a good habit to have, nevertheless.
You might have an application, which is unable to run, because of conflicting requirements.
Running
python3 -m venv my-app
will create the directorymy-app
, containing a virtual environment.After creating a virtual environment, you can activate it with
source my-app/bin/activate
on Unix, or macOS, and withmy-app/Scripts/activate.bat
on Windows.If you're using a virtual environment your prompt will show its name, e.g.
(my-app) $
.See also the section Virtual Environments, and Packages, from The Python Tutorial.