0

I'm new to Django and I wonder why it's recommended to set up a virtual environment. I asked google and found that Python provides a tool virtualenv to create an isolated Python environment.

Still, I don't get what's meant by an Isolated environment. Well, briefly my problem is that I don't understand why we need a virtual environment in simple terms.

Cyebukayire
  • 795
  • 7
  • 14
  • 3
    It's nothing specific to Django - or even Python (as other languages have similar solutions to the same problem). It's to avoid "[dependency hell](https://en.wikipedia.org/wiki/Dependency_hell)" where different projects depend on different, incompatible, versions of the same library. – Robin Zigmond Aug 08 '21 at 10:12

1 Answers1

2

You can see about python venv in PEP 405: https://www.python.org/dev/peps/pep-0405/

And there is some reasons mentioned in https://realpython.com/python-virtual-environments-a-primer/#why-the-need-for-virtual-environments:

Consider the following scenario where you have two projects: ProjectA and ProjectB, both of which have a dependency on the same library, ProjectC. The problem becomes apparent when we start requiring different versions of ProjectC. Maybe ProjectA needs v1.0.0, while ProjectB requires the newer v2.0.0, for example. This is a real problem for Python since it can’t differentiate between versions in the site-packages directory. So both v1.0.0 and v2.0.0 would reside in the same directory with the same name: /System/Library/Frameworks/Python.framework/Versions/3.5/Extras/lib/python/ProjectC Since projects are stored according to just their name, there is no differentiation between versions. Thus, both projects, ProjectA and ProjectB, would be required to use the same version, which is unacceptable in many cases.

Amin
  • 2,605
  • 2
  • 7
  • 15