3

My fabric file:

def deploy():
   code_path = 'mysite/public_html/mysite'
   with cd(code_path):
      with prefix("workon mysite"):
         run('git pull')
         run('supervisorctl -c ~/supervisord.conf restart ' + env.host_string)

I get the following error:

Aborting.
[myserv] out: /bin/bash: workon: command not found

Obviously workon command works when I do this manually (without fabric). I suspect /usr/local/bin/virtualenvwrapper.sh is not being sourced (it normally gets run through .bash_profile).

What do I need to do to get workon command working?

Trewq
  • 3,062
  • 5
  • 30
  • 48
  • Have you tried running the workon cmd on the machine you are running the fabric command on with the same user? – Greg Aug 28 '13 at 06:31

3 Answers3

7

Try modifying your prefix with:

  with prefix(". /usr/local/bin/virtualenvwrapper.sh; workon mysite"):
konsolebox
  • 66,700
  • 11
  • 93
  • 101
  • Thanks for this usefull info. I'd even say `with prefix('. /usr/local/bin/virtualenvwrapper.sh'):` then `with prefix('workon project'):` – Pierre de LESPINAY Sep 28 '13 at 08:26
  • 1
    Ok, it works but does not explain why it does not work by default. For myself, bashrc gets executed but no workon command is available. That's odd. – Jocelyn delalande Feb 17 '14 at 10:21
3

you have to copy this virtualwrapper load code from .bashrc to .bash_profile file or if not exist create new .bash_profile file and copy there.

code to copy::

export WORKON_HOME=/home/virtual
source /usr/local/bin/virtualenvwrapper.sh

this error happen because .bashrc is only read by a shell that's both interactive and non-login. So in this case it is not interactive non-login shell, so it won't work. so we have to copy those code to .bash_profile file.

reference link

Community
  • 1
  • 1
Thameem
  • 3,196
  • 4
  • 22
  • 29
0

I use pyenv with plugin pyenv-virtualenvwrapper. I had no success with workon, instead I use this (fabric 2.5):

with c.prefix('source /home/mirek/.virtualenvs/%s/bin/activate' % PROJECT):
    with c.prefix('cd /home/mirek/dj/%s/%s' % (PROJECT, PROJECT)):
        c.run('python manage.py ....')
mirek
  • 897
  • 8
  • 10