Why Should You Use virtualenv when Using Python?

Question
You were told to write a Python program in virtualenv (a layer of virtualization). Why are you being asked to do this?

Answer
Isolation of dependencies is one of the dozen factors in 12 Factor App. Using pip or pip3 on an entire Linux system to install packages for PyPI is inadvisable (according to page 32 of Expert Python Programming). This could install an older package that may have undesirable consequences. If you use virtualenv, you introduce a layer of virtualization to contain the effects of the package (according to page 360 of Expert Python Programming). The newer 4th edition of Expert Python Programming is available here.

Some jobs require a professional who uses recommended (aka best) practices. If you do not use venv for Python development, that is not going to impress your manager. If you are unsure how to use virtualenv, see this posting.

Leave a comment

Your email address will not be published. Required fields are marked *