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

Nagabhushan S N picture Nagabhushan S N · Aug 23, 2018 · Viewed 13.4k times · Source

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?

Answer

Sraw picture Sraw · Aug 23, 2018

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.