Should I be creating a virtual environment for each project?
Asked Answered
G

4

20

After googling around regarding virtualenv, I was under the impression that virtual environments should be created for every project I create (that are related and use the same site packages).

Is this true and why or why not?

Also, if I am currently using a virtualenv for one of my projects, how would I go about upgrading when upgrades for the packages come along?

Garrik answered 28/12, 2013 at 16:53 Comment(1)
you can easily upgrade packages using pip install --upgrade packagenameMaximilianus
C
7

Generally this is considered good practice. However, keep in mind that this can result in disk consumption fairly quickly if you have multiple large projects. Moreover, sometimes virtualenv may not be appropriate if you have low level system integration in your project.

If you are sharing your projects, it is good to release a requirements file for pip so people can replicate your project. Virtualenv makes this easy. One alternative to not creating unique virtualenvs for projects is to specify a requirements file and then test by creating a virtualenv and loading the requirements file and seeing if the project runs.

Clint answered 28/12, 2013 at 18:1 Comment(0)
I
1

You should always create a virtual environment. It's easy to interact with, and it allows you to avoid conflicts between projects.

Once you activate an environment, you can upgrade all packages like this:

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs pip install -U
Innerve answered 28/12, 2013 at 17:54 Comment(0)
A
1

According to this post, https://rushter.com/blog/python-virtualenv/

Only the python interpreter (executable) and a few things like pip, easy_install are copied to the local directory for your venv project. All the standard library files, such as io, random, struct ... are linked from your venv directory, not copied. So your disk space will not be going up quickly.

Arrogate answered 26/10, 2019 at 14:15 Comment(1)
Yes, but your project may have heavy requirements in terms of non-standard python modules and other external code. If you have several such projects, you may run out of disk space quickly.Grace
E
-5

Q : I was under the impression that virtual environments should be created for every project I create (that are related and use the same site packages).

Answer: No. You keep a single virtualenv for a set of projects that share same characteristics.

Q : Also, if I am currently using a virtualenv for one of my projects, how would I go about upgrading when upgrades for the packages come along?

Answer: In my view, it is difficult. You have to remember which version each virtualenv is, and how many virtualenv s you created, what characteristics each projects have, Do they break if you upgrade, Do other dependent modules break if you upload one library in them..., that itself is a pain

What I do.. I never go for virtualenv.

Ewaewald answered 28/12, 2013 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.