I recently started a Django project and I quickly realized that virtualenv will be really useful for many reasons. I set up the virtualenv and my project, but now I wonder what file I should add to my source control (in my case, Mercurial). Should I add all the files under the venv folder? How do I make sure a colleague can clone and get started to work immediately withou having to setup the env again?
You generate a “requirements” file (usually
requirements.txt) that you commit with your project:
pip freeze > requirements.txt
Then, each developer will set up their own virtualenv and run:
pip install -r requirements.txt
All these environment hassles are kind of common when you are doing python/django development! I went through all these problem, and I have tested some solutions! Things that I have tested:
- Project running local
- Project running in virtualenv
- Project running in a VM
- Project running in a VM, using vagrant
The best solution I found was #4! because the company that I used to work, each person in the team has a different OS, all sort of windows, mac and linux, and to install all dependencies for each environment it takes time! So we decided to try virtualenv, which is really good! but still each person has to setup his own enviroument. The problem in virtualenv is that all python sources are within the environment that u create! So I would not push those files to a source version control!
Best solution was #4, because that was exactly what I needed, Vagrant uses Chef to setup your environment, so you just have to write some recipes, and let vagrant run them for u! Then u push those recipes to SCM, then when the next person get the files from SCM and reloads the VM all dependencies will be automatically install!
I have a blog post explaining more about the subject as well as I have created a Django Blank project in github so you can get that to have a start point of your project using vagrant.
http://arthurnn.com/blog/2011/11/25/easy-django-quickstart/ (link no longer active, so linked to Wayback Machine)
Solution from Chris Pratt is a good one as well, however some libraries are not so straightforward to install in all OS, for instance, a lot people on Mac get problems when they want to install MySQLdb-python. which is a really common library, but if everyone in your team has to spend time solving this issues, is not good at all!