 <p>Based on <a href="http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python/5177027#5177027">Walker Hale IV's answer</a> to a similar (but distinct! ;) ) question, there are two keys to doing this:</p> <ul> <li>you don't need to install distribute and pip because these are automatically included in a new virtual environment (and you presumably only want the versions that have been tested with virtualenv)</li> <li>you can use the virtualenv source code to create a new virtual environment, rather than using the system-installed version of virtualenv</li> </ul> <p>So the workflow is:</p> <ul> <li>install Python version X on your system</li> <li>download virtualenv source code version Q (probably the latest)</li> <li>create new virtual environment with Python X and virtualenv Q</li> <li>your new VE is now running Python X and the latest stable versions of pip and distribute</li> <li>pip install any other packages</li> <li>easy_install any other packages that you can't pip install</li> </ul> <p>Notes:</p> <ul> <li>In your new virtual environment, you could install new (or old) versions of distribute, pip or virtualenv. (I think)</li> <li>I don't use WH4's technique of create a bootstrap virtual environment. Instead, I create the new virtual environment from the virtualenv source each time.</li> <li>This technique should be usable on any operating system.</li> <li>If I were explaining this to someone new to the whole Distribute/pip/virtualenv ecosystem concept, I would explain it in a virtualenv-centric way.</li> </ul> <p>I've written a bash script that does the basics in Ubuntu:</p> <pre><code> #! /bin/bash # Script to create a python virtual environment # independently of the system version of virtualenv # # Ideally this would be a cross-platform Python # script with more validation and fewer TODOs, # but you know how it is. # = PARAMETERS = # $1 is the python executable to use # examples: python, python2.6, /path/to/python # $2 is the new environment folder # example: /path/to/env_folder/name ## TODO: should be just a name ## but I can't concatenate strings in bash # $3 is a pip requirements file # example: /path/to/req_folder/name.txt # you must uncomment the relevant code below to use $3 ## TODO: should be just a name ## but I can't concatenate strings in bash # other parameters are hard-coded below # and you must change them before first use # = EXAMPLES OF USE = # . env_create python2.5 /home/env/legacy ## creates environment "legacy" using python 2.5 # . env_create python /home/env/default ## creates environment "default" using whatever version of python is installed # . env_create python3.2 /home/env/bleeding /home/req/testing.txt ## creates environment "bleeding" using python 3.2 and installs packages from testing.txt using pip # = SET UP VARIABLES = # Required version of virtualenv package VERSION=1.6.4 # Folder to store your virtual environments VE_FOLDER='/media/work/environments' ## TODO: not used because I can't concatenate strings in bash # Folder to store bootstrap (source) versions of virtualenv BOOTSTRAP_FOLDER='/media/work/environments/bootstrap' ## TODO: not used because I can't concatenate strings in bash # Folder to store pip requirements files REQUIREMENTS_FOLDER='/media/work/environments/requirements' ## TODO: not used because I can't concatenate strings in bash # Base URL for downloading virtualenv source URL_BASE=http://pypi.python.org/packages/source/v/virtualenv # Universal environment options ENV_OPTS='--no-site-packages --distribute' # $1 is the python interpreter PYTHON=$1 # $2 is the target folder of the new virtual environment VE_TARGET=$2 # $3 is the pip requirements file REQ_TARGET=$3 ## = DOWNLOAD VIRTUALENV SOURCE = ## I work offline so I already have this downloaded ## and I leave this bit commented out # cd $BOOTSTRAP_DIR # curl -O $URL_BASE/virtualenv-$VERSION.tar.gz ## or use wget # = CREATE NEW ENV USING VIRTUALENV SOURCE = cd $BOOTSTRAP_FOLDER tar xzf virtualenv-$VERSION.tar.gz # Create the environment $PYTHON virtualenv-$VERSION/virtualenv.py $ENV_OPTS $VE_TARGET # Don't need extracted version anymore rm -rf virtualenv-$VERSION # Activate new environment cd $VE_TARGET . bin/activate # = INSTALL A PIP REQUIREMENTS FILE = ## uncomment this if you want to automatically install a file # pip install -r $REQ_TARGET # = REPORT ON THE NEW ENVIRONMENT = python --version pip freeze # deactivate ## uncomment this if you don't want to start in your environment immediately </code></pre> <p>Output looks something like this (with downloading switched off and deactivation switched on):</p> <pre> user@computer:/home/user$ . env_create python3 /media/work/environments/test New python executable in /media/work/environments/test/bin/python3 Also creating executable in /media/work/environments/test/bin/python Installing distribute...............done. Installing pip...............done. Python 3.2 distribute==0.6.19 wsgiref==0.1.2 user@computer:/media/work/environments/test$ </pre>