Migrating virtualenv and github between computers

I mainly work these days with Python 2.7 and Django 1.3.3 (hosted on Heroku), and I have several projects that I support. I was working on a desktop with Ubuntu running inside VirtualBox, but recently had to make a trip and wanted everything to boot on my laptop. But I quickly found that virtualenv + Github was really easy to create projects, but I struggled to get them moving to my laptop. The approach I came up with was to create a new virtualenv and then clone the code from github. But I could not do this in the folder that I really wanted, because he would say that the folder is not empty. Thus, I would clone it into the tmp folder, than they cut / pasted everything where I really wanted it. I can’t stand it, but I just feel that I am missing something, and that it should be easier. Maybe clone first and then mkvirtualenv?

This is not a crushing problem, but I am thinking about making some changes (for example, how to drive a VirtualBox and just work with a dual boot system), and it would be great if I could make it smoother. :)

Finally, I found and read some messages about switching between git repositories between computers, but I did not see any business with Virtualenv (maybe I just skipped this).

EDIT: To be clear and to avoid confusion, I am not trying to "move" virtualenv. I'm just talking about the best way to create a new one. Install the packages and then clone the repo from github.

+8
git python github virtualenv
source share
4 answers

The only workflow you need:

git clone repo_url somedir cd somedir virtualenv <name of environment directory> source <name of environment directory>/bin/activate pip install -r requirements.txt 

It is assumed that you ran pip freeze > requirements.txt (while venv is activated) to list all the libraries dependent on virtualenv-pip and checked them in the repo.

+14
source share

This is because you do not even have to move virtualenvs to different places in one system (there is support for moving, but it is experimental), not to mention one system to another. Create a new virtualenv:

  • Install virtualenv on another system
  • Get requirements.txt either by writing one, or by saving pip freeze output (and editing the output)
  • Move the .txt requirements file to another system, create a new virtualenv and install the libraries via pip install -r requirements.txt .
  • Clone git repository on another system

For more complex tasks, you can create a bootstrap script that includes virtualenv + custom code to configure anything else.

EDIT: having a virtualenv root and the root of your repository in the same directory seems like a very bad idea to me. Place the repository in the directory inside the virtualenv root or put them in completely separate trees. You not only avoid git (by right - usually everything that is not tracked by git is a fair game to delete) by complaining about existing files, you can also use virtualenv for several repositories and avoid name conflicts.

+9
source share

In addition to creating a script that creates a new virtualenv, you must create a requirements.txt file with all your dependencies (e.g. Django1.3), then you can run pip install -r requirements.txt and this will install all your dependencies for you.

You can even create pip for this by doing pip freeze > stable-req.txt , which will print your dependencies as they are in your current virtualenv. Then you can save the requirements.txt file under version control.

+3
source share

The nice thing about virtualenv is that you can describe how to create it, and you can do it repeatedly on multiple platforms.

So, instead of cloning all of this, clone the method to create virtualenv sequentially and use this in your git repository. This way you avoid platform-specific nasty things.

+1
source share

All Articles