Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using virtualenv on Ubuntu 12 and when I install packages with pip (after activating the virtualenv) the packages are not being installed in the environment's site-packages directory, they're ending up in the server's dist-packages directory. When setting up the venv I added the --no-site-packages.

I think this is an issue with Ubuntu using dist-packages instead of site-packages, but how can I get virtual environments working?

share|improve this question
    
Make sure pip is actually installed into the venv, or use "./bin/pip" instead of simply "pip". –  pyroscope Jun 13 '12 at 19:59
    
If pip is already installed on the system before the venv is created, how can I force install pip into the venv if it already exists and can be found on the system outside the venv? –  Michael Waterfall Jun 14 '12 at 13:07
1  
./bin/easy_install -U pip –  pyroscope Jun 14 '12 at 18:14
add comment

1 Answer

Try this to create your virtualenv:

#! /bin/bash
#
# Create a Python virtualenv using current code (not the distribution's outdated one)
#
PYTHON=/usr/bin/python2
test -x $PYTHON || PYTHON=/usr/bin/python

# You can provide an alternative Python executable as the first argument, this
# can for example be an interpreter installed into ~/.pythonbrew
if test -x "$1"; then
    PYTHON="$1"
    shift
fi

# Be nice to github (get current source only once per day)
venv_cached=/tmp/$USER-virtualenv-$(date +'%Y-%m-%d').py
venv='https://github.com/pypa/virtualenv/raw/master/virtualenv.py'
test -f $venv_cached || \
    $PYTHON -c "import urllib2; open('$venv_cached','w').write(urllib2.urlopen('$venv').read())"

# Call virtualenv
deactivate 2>/dev/null || true
$PYTHON $venv_cached "$@"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.