• Do you need to work on any other computers than yours in which you do not want to (cannot) install everything you want?
  • Do you want to bring with you on a USB stick your working Django development environment and your projects?

Then, follow this tutorial. My goal was to be able to bring with me my django development environment and my projects on a USB stick everywhere, fully working on any Windows computers without any setup.

It includes:

  • Python
  • Django
  • Git
  • Bash Shell (shipped with Git)
  • virtualenvs fully working
  • pip available to install packages

 

First of all, let me explain the global structure of the folders:

 

1. Install Python and Git

(These steps must be done just once.)

  • Install Portable Python

Unzip it in development/tools/PortablePython

You can install it without any modules, you will be able to install the ones you want later.
  • Install Portable Git

Get it from http://code.google.com/p/msysgit/downloads/list

Unzip it in development/tools/PortableGit

 

 2. Setting up virtualenv and virtualenvwrapper

(These steps must be done just once.)
  • Launch the Bash shell by double clicking on launch.bat
  • Install pip: (see more on the pip website)

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

  • Install virtualenv & virtualenvwrapper via pip:

pip install virtualenv virtualenvwrapper

  • Modify tools\PortablePython\App\Scripts\virtualenvwrapper.sh:

Look for “function workon“.
Add the following code after this block:

(You can use the file development\tools\virtualenvwrapper.sh_modification.txt shipped with the zip to copy/paste the code.)

 

3. Setting up Git

  • Modify tools\PortableGit\etc\git-completion.bash:

Add at the end of the file:

(You can use the file development\tools\git-completion.bash_modification.txt shipped with the zip to copy/paste the code.)

 

4. Creating a virtual env

  • Launch the Bash shell by double clicking on launch.bat
  • Use mkvirtualenv:

mkvirtualenv <VIRTUALENV_NAME>

Use the name you want for you virtual env.
Make sure to use the same <VIRTUALENV_NAME> in the next steps.

By the way, you might see the following error which also appears when you launch the .bat:

bash: mktemp: command not found ERROR: virtualenvwrapper could not create a temporary file name.

No worries, I could not get rid of it but everything will work anyway.

  • Modify launch.bat:

Uncomment the following line and change <VIRTUALENV_NAME> by the name you chose for your virtual env:

echo %PYTHON_ROOT%\App > %VIRTUALENVS_ROOT%\<VIRTUALENV_NAME>\Lib\orig-prefix.txt

  •  Modify tools\virtualenvs\<VIRTUALENV_NAME>\Scripts\activate:

Look for “export VIRTUAL_ENV” and replace it by:

export VIRTUAL_ENV=$MY_PATH/tools/virtualenvs/<VIRTUALENV_NAME>

Do not forget to change <VIRTUALENV_NAME> by the name you chose for your virtual env.

You are now able to use your virtual env:

workon <VIRTUALENV_NAME>

You will see the name of your virtual env between parenthesis when you are working on it.
You can now install almost any packages you want into your virtual env by using pip. (lxml cannot be install via pip, check out my article about Installing lxml in a simple and quick way on Windows)
For example:

pip install django ipython yolk

To exit it, just type: deactivate

 

This is the end of the tutorial, I hope some people will find it useful.

Feel free to leave comment and/or send me your feedback to improve this “homemade” solution.

I wanted to keep this tutorial as simple as possible so I did not talk about PostgreSQL but if you are interested about using PostgreSQL on this portable environment, let me know.

 

NB: This tutorial has been tested with these versions:

  • PortablePython 2.7.3.1
  • PortableGit-1.7.11-preview20120710