PyCharm虚拟环境和Anaconda环境有什么区别? [英] What is the difference between PyCharm Virtual Environment and Anaconda Environment?

查看:1195
本文介绍了PyCharm虚拟环境和Anaconda环境有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在PyCharm中创建一个新项目时,它会创建一个新的虚拟环境.我已经读过,当我执行Python脚本时,它们是在此环境中而不是系统环境中使用解释器执行的.因此,如果需要安装某些软件包,则只​​能在此环境中安装它们,而不能在系统环境中安装它们.太酷了.

When I create a new project in PyCharm, it creates a new Virtual Environment. I have read that when I execute Python scripts, they are executed using the interpreter in this environment instead of System Environment. So, if I need to install some packages, I can install them in only this environment and not in the system environment. That's cool.

我还阅读了有关Anaconda Environment的信息.当我创建一个新的Anaconda环境时,它会创建一个与系统环境分开的新环境.对于我的项目,我可以使用此环境并仅在此处安装必需的软件包,而不能在主系统环境中安装.

I have also read about Anaconda Environment. When I create a new Anaconda environment, it creates a new one apart from system env. For my projects, I can use this environment and install only the required packages here and not in the main system environment.

现在,我的问题是PyCharm创建的虚拟环境与Anaconda创建的环境之间有什么区别? PyCharm创建的虚拟环境约为15-20MB,而Anaconda的虚拟环境为90MB.因此,一定有区别.另外,我读到可以配置PyCharm以使用Anaconda Environment解释器.

Now, my question is what is the difference between virtual environment created by PyCharm and the environment created by Anaconda? The virtual env created by PyCharm is around 15-20MB while that of Anaconda is 90MB. So, there must be a difference. Also, I have read that I can configure my PyCharm to use the Anaconda Environment interpreter.

那么,PyCharm和Anaconda创建的环境之间有什么区别?

So, what is the difference between the environments created by PyCharm and Anaconda?

推荐答案

我必须澄清anaconda只是一个集合.实际的环境管理器是conda. 此处miniconda.它仅包含管理环境所需的部分,而不是完整的anaconda集合.

I have to clarify that anaconda is just a collection. The real environment manager is conda. Here is miniconda. It just contains the necessary parts to manage the environment instead of a full anaconda collection.

conda不仅是简单的Python软件包管理器,还是系统级的软件包管理器.它将帮助您轻松安装软件包.一个经典的示例是在Windows上安装numpy.如果没有conda,这确实很困难,因为它需要一个很难获得的特定C编译器.但是,使用conda,您只需一个命令conda install numpy即可安装numpy.它将自动解决编译器问题和C依赖性.

conda is beyond a simple Python packages manager but is a system-wide package manager. It will help you to install packages without pain. A classic example is installing numpy on Windows. Without conda, it is really difficult as it needs a specific C compiler which is difficult to obtain. But with conda, you can install numpy with just one command conda install numpy. It will automatically solve compiler problem and C dependencies.

所以回到您的问题,当您在Pycharm中创建一个env时,它将询问您要创建哪个env:Virtualenv EnvironmentConda EnvironmentPipenv Environment.对于我来说,我通常选择Pipenv Environment,因为此环境将绑定到当前项目并可以生成一个锁定文件.

So back to your question, when you create an env in Pycharm, it will ask you which env do you want to create: Virtualenv Environment, Conda Environment, or Pipenv Environment. As for me, I usually choose Pipenv Environment as this env will be bound to the current project and can generate a lock file.

在这种情况下,我想您现在可以理解:没有一个名为由PyCharm创建"或"Anaconda"的环境.只有名为由Virtualenv,Conda或Pipenv创建"的环境.而Pycharm只是使用并包装其中之一.

In this case, I think you can understand it now: There isn't an env named "created by PyCharm" or "Anaconda". There are only envs named "created by Virtualenv, Conda or Pipenv". And Pycharm just uses and wraps one of them.

那么Conda EnvironmentVirtualenv Environment之间有什么区别(Pipenv Environment本质上是具有复杂的pipVirtualenv Environment)?不同之处在于它们的用途不同.

So what is the difference between Conda Environment and Virtualenv Environment(Pipenv Environment essentially is a Virtualenv Environment with sophisticated pip)? The difference comes from their different purposes.

Conda Environment通常用于"Python用户".他们使用Python作为工具来完成其他一些工作,例如网络爬网,数据挖掘和图像处理.他们对Python不太了解(因为他们不需要知道),因此conda是尽可能自动的.它们的任务可以在计算机中的任何位置,因此conda创建的环境位于用户范围的目录中.他们有时需要不同的Python版本,可以在conda中完成,而不能在virtualenv中完成.

Conda Environment is usually for "Python user". They use Python as a tool to do some other works such as web crawling, data mining, and image processing. They don't know much about Python(as they don't need to know) so conda is as automatical as possible. And their tasks can be anywhere in the computer so the envs created by conda are located in user-wide directories. And they sometimes need different Python versions, this can be done in conda but not virtualenv.

Virtualenv Environment通常用于"Python开发人员".他们使用Python来构建应用程序或程序包. Virtualenv创建的环境通常位于当前项目的目录中.因此,您可以为每个应用程序创建一个环境,并轻松管理依赖项.

Virtualenv Environment is usually for "Python developer". They use Python to build applications or packages. The envs created by Virtualenv are usually located in the current project's directory. So you can create an env for every application and manage dependencies easily.

总结:

Conda Environment:

  1. 不仅管理Python软件包,而且还管理不同的Python版本和系统范围的依赖项.
  2. 环境位于用户范围内的目录中.
  3. 更少的环境.

Virtualenv Environment:

  1. 管理Python软件包.主要目的是为每个应用程序分离依赖项.
  2. 环境通常位于项目范围的目录中. (尽管pipenv默认情况下在用户范围的目录中创建env,但许多人认为项目目录应为默认目录.)
  3. 更多的环境(每个应用程序都有一个新的环境)
  1. Manage Python packages. The main purpose is to separate dependencies for every application.
  2. Envs are usually located in project-wide directories. (Although pipenv creates env in user-wide directories by default, many people think in project directories should be the default.)
  3. Much more envs.(A new env for every application)

对我来说,我会同时使用它们.我使用conda管理不同的Python版本,并使用pipenv管理我的应用程序的依赖关系.

For me, I use both of them. I use conda to manage different Python versions and use pipenv to manage dependencies for my applications.

这篇关于PyCharm虚拟环境和Anaconda环境有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆