1

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 ?

Emanuel
  • 640
  • 1
  • 7
  • 25
  • You shouldn't put your project code to virtualenv, these are different directories. – bakatrouble Aug 10 '17 at 14:41
  • 1
    Keep project separate. virtualenv just helps you to provide custom pythonpath after it is activated. So libraries you install in such environment will be available only after activation or virtualenv profile. – simar Aug 10 '17 at 14:42
  • 1
    What about putting the `virtualenv` into `django_site` directory? –  Aug 10 '17 at 14:42
  • @bakatrouble and @simar do you mean that I can do something like: `C:\projects\django_venv` and the django site will be at `C:\projects\django_site`, is it legit ? ? And @Chris I feel like this is not the right way to do it. – Emanuel Aug 10 '17 at 14:48
  • 1
    @SpazaM yeah, that's the correct way to do it. Keep your dajngo project and virtualenv next to each other. – v1k45 Aug 10 '17 at 15:04
  • @v1k45 actually @chris idea pretty clean when you look from outside, but it's mean that I need to put all virtualenv directories in `.gitignore`. If I dont use his idea, for every project that I have in `c:\projects` I need also `virtualenv` dir. – Emanuel Aug 10 '17 at 15:09
  • 1
    It is common knowledge to put virtualenv directory name in `.gitignore` file. See https://github.com/github/gitignore/blob/master/Python.gitignore#L81 – v1k45 Aug 10 '17 at 15:12
  • @v1k45 So what do you say ? chris idea or next to each other ? – Emanuel Aug 10 '17 at 15:24

1 Answers1

1

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.

Community
  • 1
  • 1
Emanuel
  • 640
  • 1
  • 7
  • 25