Virtualenv and source version control

后端 未结 2 836
臣服心动
臣服心动 2020-12-04 08:15

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 w

相关标签:
2条回答
  • 2020-12-04 08:58

    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:

    1. Project running local
    2. Project running in virtualenv
    3. Project running in a VM
    4. 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)

    EDIT

    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!

    0 讨论(0)
  • 2020-12-04 09:00

    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
    
    0 讨论(0)
提交回复
热议问题