Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using virtualenv with legacy Django projects

I am finally going to start using virtualenv for my Django projects on my development machine. Before I start I want to know if there are any special considerations for dealing with my existing projects. My presumed workflow is something like:

  1. make a new virtualenv
  2. activate the new virtualenv
  3. Install Django in there
  4. pip install all the packages I know I need for my existing project
  5. copy my Django project files, app files, and git files into the project folder within the virtualenv.

Edit 6. make requirements file for deployment

This is obviously very simplified but are there any steps or considerations I am fundamentally missing? Is git going to be happy about moving? Also is it best practice to have a separate virtualenv for each Django project?

I know this is not a typical code problem, but I hope those that know more than I do can point me in the right direction.

Many thanks.

like image 919
Darwin Tech Avatar asked Mar 21 '12 16:03

Darwin Tech


1 Answers

I don't see any big issue on migrating your projects and I think your 5-steps plan is correct, in particular, for steps 3/4/5 (I'd merge them), you can handle project dependencies with pip, possibly using requirement files.

Requirement files are plain text files telling to pip which packages have to be installed in your virtualenv, included your git-tracked projects which eventually can be deployed in your virtual environment as development eggs (they bring with them version control infos). Once you have a req file, it's a matter of:

pip install -r file.req

to have all needed packages installed in your env. As you can see from virtualenv docs, a typical req file would contain something like:

django==1.3.0
-e git://git.myproject.org/MyProject.git#egg=MyProject

I usually keep each project in its own virtualenv, so I can deploy it to the production server the same way I do for local development.

like image 173
Masci Avatar answered Sep 20 '22 03:09

Masci