hkhr hkhr - 1 year ago 90
Python Question

importance of virtual environment setup for django with python

I am very much new to the process of development of a web-application with django, and i came across this setting up and using virtual environment for python.
So i landed with some basic questions.

  1. What does this virtual environment exactly mean.

  2. Does that has any sort of importance in the development of web-application using django and python modules.

  3. do i have to worry about setting up of virtual environment each time
    in the development process.

Answer Source
  1. A virtual environment is a way for you to have multiple versions of python on your machine without them clashing with each other, each version can be considered as a development environment and you can have different versions of python libraries and modules all isolated from one another
  2. Yes it's very important, if you're working on an open source project for example and that project uses django 1.5, on the other hand you don't have a virtualenv and you installed django 1.9 it's almost impossible for you to contribute because you'll be having a lot of errors are supposed bugs, due to the fact that you aren't running the version of django that was used for the project, if you decide to uninstall and downgrade to that version, then you can't have django 1.9 anymore for your personal project. A virtualenv handles all this for you by enabling you to create seperate virtual (development) environments that aren't tied to each other and can be activated and deactivated easily when you're done.

  3. You're not forced to but you should, it's as easy as

    virtualenv newenv

    cd newenv

    source bin/activate # This current shell is now uses the virtual environment

    Moreover it's very important for testing, lets say you want to port a django web app from 1.5 to 1.9, you can easily do that by creating different virtualenv's and installing different versions of django. it's impossible to do this without uninstalling one version (except you want to mess with sys.path which isn't a good idea)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download