What is the difference between PyCharm Virtual Environment and Anaconda Environment?

限于喜欢 提交于 2020-07-16 16:09:21

问题


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.

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.

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.

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


回答1:


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 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.


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.

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.


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 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 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.

To sum up:

Conda Environment:

  1. Manage not only Python packages but also different Python versions and system-wide dependencies.
  2. Envs are located in user-wide directories.
  3. Fewer envs.

Virtualenv Environment:

  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)

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




回答2:


Both environments are based on python's virtualenv, you can use them independently and configure (or install) packages inside it as you need, without the worry of conflicts. This is the essence of virtualenv.

Anaconda is a python distribution (just like linux distros) it by default add other packages based of it's opinion of what developers need. Hence, the installation is larger than if you install plain vanilla python. This is also why it's virtual environment is quite large.

Pycharm is an IDE, which happens to support the virtualenv feature of python. So it can create it for you, if you wish. It can use plain python distro to create it, so this will have a smaller size than if it uses a distro like Anaconda, as you have noticed.

The size issue is not specific to Anaconda, if you list all packages installed for you by anaconda conda list and install it manually yourself in the "lightweight" virtualenv you will see the size go up too. I believe you get my point.



来源:https://stackoverflow.com/questions/51978816/what-is-the-difference-between-pycharm-virtual-environment-and-anaconda-environm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!