Virtualenv and Django in Production

532 views
Skip to first unread message

adrian s

unread,
Sep 20, 2011, 1:55:17 AM9/20/11
to django...@googlegroups.com
Hi all, I've been using virtualenv as recommended in my development environments. 

I am now migrating a project which was not using virtualenv, to another server and now
have the opportunity to use it in production.

I've spent a while googling this subject and I'm not sure what the best practice is.
Is it common to run a production django deployment with apache behind virtualenv? If so,
could anyone steer me in the proper direction for getting this setup with the wsgi file...

Or, is virtualenv best for just testing isolated environments, and running production
with the existing global space (I feel naive typing this out, so I must be wrong (: )
 as is (isn't there more overhead with virtualenv anyhow?)

I hope I made sense.

If anyone has any relevant docs that clarify this (maybe my searches stink) I'd love to read
over what there is so I may make an appropriate call.

Adrian

Preston Holmes

unread,
Sep 20, 2011, 8:24:29 AM9/20/11
to Django users
How you use a virtualenv in production depends on all the parts of
your production stack. If you are using mod_wsgi, search mod_wsgi +
virtualenv, gunicorn, etc

You might also consider one of the new "platform-as-a-service" hosting
options that basically solve this for you.

-P

Matt Schinckel

unread,
Sep 20, 2011, 8:27:38 AM9/20/11
to django...@googlegroups.com
I use virtualenv in production. It means you can install python packages using pip without having root or sudo access on the server.

You can also isolate installs, and use no-site-packages.

I can't think of a reason not to use it.

Matt.

DrBloodmoney

unread,
Sep 20, 2011, 8:28:07 AM9/20/11
to django...@googlegroups.com

I run a VPS with several django apps isolated into different
virtualenvs. They are served by either uwsgi or gunicorn and reverse
proxied by nginx. There are several good guides if you google for some
of those keywords.

It is a pretty easy set-up. If you were only serving one django app,
it may be slight overkill, but it may be worth the effort to get it
set up this way so you can easily add more django applications and
have them be completely isolated from each other.

dm03514

unread,
Sep 20, 2011, 11:35:51 AM9/20/11
to Django users
Virtualenv provides you with more control over your production
environments. We run apache/virtualenv on 10 of our production
servers.
There very well might be more overhead running through a virtualenv.
For us it is too negligible to make a difference.

We use fabric to deploy our django apps, and automatically initiate
virtualenvs, or update virtualenvs on remote servers. I think virtual
env is great on production because it keeps all of our environments on
the same page. ie. If we update a python package to a newer version,
or roll it back to an older version. All we have to do is make the
appropriate changes in our code, change the package version entry in
our bootstrap.py file and deploy through fabric, no manually managing
packages on our production servers, nice and simple

Tom Evans

unread,
Sep 20, 2011, 11:53:33 AM9/20/11
to django...@googlegroups.com

There is no more overhead in virtualenv than there is in python
itself. To understand why, you should look at how and why virtualenv
works - you are using a different python interpreter, so that python
interpreter looks in a different place than the stock interpreter.

virtualenv is entirely free magic that makes your deployments more
consistent and repeatable. Use it!

Cheers

Tom

Markus Gattol

unread,
Sep 20, 2011, 12:14:37 PM9/20/11
to django...@googlegroups.com
 - it's just symlinks i.e. not more overhead
 - you won't clutter your system Python or vice versa when you up/downgrade something
 - if you want a production setup use e.g. gunicorn/nginx or even better uwsgi/mongrel2
 - as all the others here, I can strongly recommend using a virtualenv for production as well as for development

Tim Sawyer

unread,
Sep 20, 2011, 3:30:41 PM9/20/11
to django...@googlegroups.com
Has anyone any instructions for using VirtualEnv with Hudson/Jenkins?

Thanks,

Tim.

shadowy m

unread,
Nov 27, 2013, 1:48:09 PM11/27/13
to django...@googlegroups.com, list....@calidris.co.uk
Yes, I would like to know to also.  This has been typical of my Django/Python experience.  The OP asked how and that they could not find good documentation and got several responses of why and "google it, lots of good info".

Maybe good info if you already mostly know what you are doing and code Python all the time.  You can find all the little bits and pieces but nobody ever seems to put it together in a way beginners/intermediates who are not necessarily professional coders can work with.  Django/Python has a LOOONg way to go in this respect in order to catch up with more mature technologies like PHP imho.

There is still no good consise, simple, organized info for this sort of deployment even though this thread was stared 2 years ago.  So things don't seem to have improved.

Timothy W. Cook

unread,
Nov 27, 2013, 3:09:36 PM11/27/13
to django...@googlegroups.com, list....@calidris.co.uk
Interesting in how you think that PHP is more mature and better
documented than Python.

Anyway, the OP asked about virtualenv with Hudson and Jenkins, not
about Django. So maybe they asked in the wrong place.

Django running virtualenv is quite well documented. But any Python
app runs the same under virtualenv. That is kind of the point. So
the first step is to learn about virtualenv. Then install Django
inside a virtualenv.

Yes using Google is a valid answer when you want to get opinions about
two pieces of software working together. The Django docs can't (and
shouldn't) cover all the possible combinations.

If you google those two combinations there are tutorials for them.

When I ask specific Django questions here; as a VERY much newbie. I
get great answers and even followups when I don't understand how
something is working.

So your evaluation of the community is flawed. Yes the docs are a
little confusing at first. But the tutorial is awesome and you just
have to keep looking or ask a specific question.


Cheers,
Tim
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/25528fbd-1e42-4bc5-9301-56a549d71ee9%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
Reply all
Reply to author
Forward
0 new messages