Is virtualenv recommended for django production server? [closed]

I would do it that way if you ever think you'll run more than one project on the webserver. As soon as you have two projects you run the risk of a future upgrade of any python package breaking the other site.


Is virtualenv recommended for django production server?

Yes, it makes your project not depend on certain aspects of the system environment and also it allows you to make the deployment process more clear and configurable.

I use fabric, pip and virtualenv to deploy all my Django projects.


Yes, I think you should use virtualenv to deploy it into production. It makes things a lot easier and cleaner for you, especially if you plan on deploying multiple services, e.g. django based websites or other python projects. You don't want each of them to be polluting the global python environment with their packages.

I think virtualenv will help you manage all your dependencies cleanly.

To update your production env all you need to do is to:

pip -r name_of_your_requirements_file.txt

I use virtualenvs in production, and you can use uWSGI to serve the applications, with Cherokee as a web server.

To use your virtualenv in production, you will need to add its path to your PYTHONPATH.

For example if your env has the path "/home/www/my_project/env/", the path to add would be:

/home/www/env/lib/python2.7/site-packages/

You can set this up in many different ways, but if you're generating your FCGI or uWSGI interface through manage.py, simply add the following at the very top of your manage.py (before the rest):

import os
my_virtualenv_path = "/home/www/my_project/env/lib/python2.7/site-packages/"
# Add it to your PYTHONPATH
os.path.append(my_virtualenv_path)

You can adapt this to your setup, just in case you could also do the following in the shell:

export PYTHONPATH:$PYTHONPATH:/home/www/my_project/env/lib/python2.7/site-packages/

You will also need to add the directory that contains your settings.py file to the PYTHONPATH, so Django will be able to discover it. Just proceed in a similar manner to do so.