I've gotten the following to work on my own machine:
with cd("~/somedir"), prefix("source ~/.virtualenvs/venv/bin/activate"):
with cd("anotherdir"):
run("ls")
The real question I have is, once you activate the virtualenv, why do you need to cd into another directory? This should work just fine for your purposes if you just want to install something using pip
with cd('/my/virtualenv/dir/'), prefix('source bin/activate'):
run('pip install something')
I got the with cd("dir"), prefix("stuff")
idea from the fabric docs btw
EDIT:
As an update to my answer: Why not just use two absolute paths?
with cd("/abs/path/to/my/file"), prefix("source /abs/path/to/my/venv/bin/activate"):
run("pip install something")
run("./somefile.py")
Fabric will execute a command similar to what you were trying to input:
Executed: /bin/bash -l -c "cd /abs/path/to/my/file && source ~/abs/path/to/my/venv/bin/activate && pip install something"
Then it will run
./somefile.py