Should I be creating a virtual environment for each project?

不问归期 提交于 2020-07-06 10:33:06

问题


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?


回答1:


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.




回答2:


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



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/20816984/should-i-be-creating-a-virtual-environment-for-each-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!