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?
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
:
Virtualenv Environment
:
pipenv
creates env in user-wide directories by default, many people think in project directories should be the default.)For me, I use both of them. I use conda
to manage different Python versions and use pipenv
to manage dependencies for my applications.