Search code examples
pythondjangovirtualenvdirectory-structure

virtualenv and Django directories structure


I was trying to use virutalenv in windows but there is something odd that I barely understand about the directories structure.

When you create a new virtual environemnt it creates for you the following structure:

C:\Projects\djang_venv\
   Include\
   Lib\
   pip-selfcheck.json
   Scripts\
   tcl\

If I want to work on my django project where should I put my project, in the django_vent directory ?

C:\Projects\djang_venv\
   django_site\
   Include\
   Lib\
   pip-selfcheck.json
   Scripts\
   tcl\

It's not looking right, like something is messy here.

Where should I put my application when I create a virtual environment ?


Solution

  • Found out that someone already asked the same question

    And actually one of answers (Not the accepted one) was a very informative and clear (Will include his answer in my conclusion)

    This is what I understood from the research I did on virtual environments world in Python:

    1. First of all, it's a matter of opinion. But it is important to note that the experience of the people should be considered, because it is possible to know which method is more appropriate to choose, since the guys with experience understood which method was not good over time.

    2. If you want to stick with virtualenv, one of the solutions keep your directories structure pretty clean outside, Projects directory will stay organized. Put all the virtual environments into one folder, and name each of them after the project you are working on:

    c:\projects\virtualenvs\
       django_site\  <-- Virtual environment for Django project
       flast_site\   <-- Virtual environment for Flask project
    c:\projects\django_site\  <-- Django project
    c:\projects\flask_site\   <-- Flask project
    

    But it's a bit messy with the source command:

    cd /django_site
    source ../virtualenvs/django_site/bin/activate
    
    1. To get the most organized environment, without any headache about the order of the virtual environments directories, there is a wrapper for virtualenv called (surprisingly) virtualenvwrapper. All the virtual environments are stored away from you in your HOME_USER directory, for me it's c:\users\my_user\.virtualenvs. And you get great shortcuts by the package, like mkvirtualenv which creating for you a virtual environment no matter where are you in the file system, then you can switch between the virtual environments with the shortcut workon, Some examples:
    $ mkvirtualenv flask_site
    New python executable in c:\users\usr\.virtualenvs\flask_site\Scripts\python.exe
    Installing setuptools, pip, wheel...done.
    
    (flask_site)$ workon
    flask_site
    
    (flask_site)$ mkvirtualenv django_site
    New python executable in C:\Users\Emilman\.virtualenvs\django_site\Scripts\python.exe
    Installing setuptools, pip, wheel...
    
    (django_site)$ workon
    django_site
    flask_site
    
    (django_site)$ workon flask_site
    (flask_site)$
    

    Actually after checking all the options, I've chosen the virtualenvwrapper. great solution for virtual environments world in Python.