Enviroments in Virtual Env
The importance of using environments
As was said in Setting environments in Python it’s important to use environments for your deployment, even if these are side projects or wild repositories. But at first, I used Conda to create the environment. However, a while ago, I made the switch to Virtual Env As a point of order. So, we’re going to see how to create and activate the environment in virtual env. You can find all the information in Python’s official documentation: venv — Creation of virtual environments
Important Commands and steps in Virtual env
When i use the virtual env I follow this steps:
Got to the folder where I want to create the env. Generally is under the project. And run the following command:
python3 -m venv nameoftheenv
Example:
python3 -m firstenvcreated
You can see the the environment created in the folder:
If you want to activate the environment you have to go to bin and activate the environment and run:
source activate
If you want to deactivate the virtual env you can run
deactivate
If you know in detail this simple steps you can follow this gist with more commands: How to install virtualenv
Is it better than Conda env?
Now, I’m using more virtual env rather than Conda because with the first, I can create the environment folder in a specific place that can select. Usually, i create the environment in the root folder of the project. For example:
name_of_project\.env
This is useful for me because I notice that I’ve started to have some side projects, so I have different environments; and when I try to remember by name, I really can’t do that. So, Having a special location for the environment, it’s useful. For that reason, I prefer virtual env rather than Conda.
Another important reason for using virtual env is that you can find it natively when installing python. It’s not hard to use it. At least, you decided to install python using Anaconda. Which is another world.