Do you want the packages or libraries to be installed in a separate folder, so that you don't want to mix up with other files inside your system?
The best ways is to create an environment where you can store all the packages for your project.
A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.
We can do it in just two steps in windows machine:
- Create the environment:
$ python -m venv env
***** env is an environment name, you can give it any name.
- Activate the virtual environment
$ .\env\Scripts\activate
Now we can install any packages inside it. For example if you want to install django in the environment, you can do it by
$ pip install django
Top comments (3)
Super honest, and a sorta-pointed question: Why venv?
I ask purely out of curiosity, I feel the same way about venv that I do any virtual environment manager. I haven't found one I like more than others so I'm curious to hear the opinions of other python devs.
venv allow us to manage separate package installations for different projects. If we are using Python 3.3 or newer versions, venv module is the preferred way to create and manage virtual environments. Also, venv is included in the Python standard library and requires no additional installation.
In case of Python 2, we need to install the virtualenv or maybe some others might be there too.
I use the above mentioned commands in my windows machine when I have to install dependencies for my Python projects. I didn't use much on other os, but I would say reason we use virtual environment remains same.
Awesome, thank you!