I would like to use a conda virtual environment with fabric2. I see some advice for fabric1 and some packages to handle this. But it seems like there should be an easy way to do this with fabric2. Normally I activate with $source activate myenv
Asked
Active
Viewed 361 times
1

Vadim Kotov
- 8,084
- 8
- 48
- 62

Bernie2436
- 153
- 1
- 6
-
I wonder if my solution was helpful?! – Peshmerge Nov 12 '18 at 12:35
2 Answers
1
I would assume you have already created the virtual environment, then what you have to do is:
from fabric import task
@task(hosts=["servername"])
def do_things(c):
with c.cd('your_dir'):
# assuming you already added myenv to your path
with c.prefix('source activate myenv'):
c.run('pip3.6 install -r requirements.txt') #for example if you have pip3.6
You have to use with c.prefix()
to enable using that environment! And remember you have to run everything within the scope of with c.prefix('source activate myenv'):
if you want to use the virtual environment.

Peshmerge
- 1,024
- 1
- 14
- 27
1
@Peshmerge's answer works for me. But we do need to keep in mind that fabric2 would use the default bash shell. If you use conda init zsh
before, you have to do it again for the bash shell: conda init bash
.

whyisyoung
- 316
- 5
- 16