Where should virtualenvs go in production?
Asked Answered
C

1

9

When using virtualenv (or virtualenvwrapper), the recommended practice is to group all your virtual environments together ... for example in ~/.virtualenvs

BUT, I've noticed in reading a number of articles on deploying Django applications, that the recommendation seems to be to put your virtual environments somewhere under the root of the individual web application ... for example in /srv/www/example.com/venv.

My questions are:

  1. Why?

  2. Would it matter if I went one way or the other?

  3. And is one way recommended over another?

Candide answered 23/4, 2014 at 23:36 Comment(2)
If you have one project on server,you don't need virtualenv.If you have multiple projects then install vittual env and you can make env any place you want ./home/ /www/.Fomentation
@PraveenSinghYadav Even if you only have one project, there are still benefits to using virtualenv to isolate the project dependencies from the system Python. System upgrades will not break your project and vice versa. Tools like pip freeze will reflect the project requirements, not the state of the system Python which may include extra packages not needed for the project. It's a best practise to use a virtualenv for a Django project.Incomprehensible
I
2

Here are my thoughts:

Arguments for grouping in a common folder

  • Cleaner management of multiple venvs on a given machine. Good tools to support checking which are available, adding new ones, purging old ones, etc.
  • More sensible (and more space-efficient) when sharing one or more venvs across more than one project
  • Allows the use of some nice features like autocompletion of venv names

Arguments for keeping with the project

  • Clear relationship between the venv and the project. Eliminates any ambiguity and less error-prone since there's little chance of running the wrong venv for a project (which is not always immediately evident).
  • Makes more sense when there is a one-to-one relationship between venvs and projects
  • May be the preferred approach when working in teams from separate accounts.
  • More straightforward when deploying across identical hosts; (just rsync the whole project). Nothing stopping you from doing this with a venv in a common folder, but it feels more natural to deploy a single tree.
  • Easier to sandbox the whole application.

I tend to prefer the former for more experimental / early-stage work, and the latter for projects that are deployed.

Incomprehensible answered 24/4, 2014 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.