How to install python packages in virtual environment only with virtualenv bootstrap script?
Question: I want to create a bootstrap script for setting up a local environment and
installing all requirments in it. I have been trying with
virtualenv.create_bootstrap_script as described in their
[docs](http://pypi.python.org/pypi/virtualenv).

    
    
    import virtualenv
    s = virtualenv.create_bootstrap_script('''
    import subprocess
    def after_install(options, home_dir):
      subprocess.call(['pip', 'install', 'django'])
    ''')
    open('bootstrap.py','w').write(s)
    

When running the resulting bootstrap.py, it sets up the virtual environment
correctly, but it then attempts to install Django globally.

How can I write a bootstrap script that installs Django only in this local
virtual environment. It has to work on both Windows and Linux.


Answer: You could force pip to install into your virtualenv by:

    
    
    subprocess.call(['pip', 'install', '-E', home_dir, 'django'])
    

Furthermore, it is a nice and useful convention to store your dependencies in
requirements.txt file, for django 1.3 that'd be:

    
    
    django==1.3
    

and then in your `after_install`:

    
    
    subprocess.call(['pip', 'install', '-E', home_dir, '-r', path_to_req_txt])
    

