重现的步骤:
~/Desktop/fab
通过发出fabfile.py
运行此./fab目录中的fab init
:
#!/usr/bin/env python
#set up ssh to remote server
import sys, os, fileinput
from fabric.api import *
def init():
local('mkdir ./virtualenv')
local('cd ./virtualenv && virtualenv --no-site-packages venv')
local('chown -R user:user ./virtualenv/')
local('chmod 770 -R ./virtualenv/')
venv = 'source ./virtualenv/venv/bin/activate && '
local(venv+'pip install mysql-python django South')
收到此错误:
➜ fab fab init
[localhost] local: mkdir ./virtualenv
[localhost] local: cd ./virtualenv && virtualenv --no-site-packages venv
New python executable in venv/bin/python
Installing distribute...........................................................................................................................................................................................................................done.
Installing pip................done.
[localhost] local: chown -R user:user ./virtualenv/
[lcalhost] local: chmod 770 -R ./virtualenv/
[localhost] local: source ./virtualenv/venv/bin/activate && pip install mysql-python django South
/bin/sh: 1: source: not found
Fatal error: local() encountered an error (return code 127) while executing 'source ./virtualenv/venv/bin/activate && pip install mysql-python django South'
Aborting.
从zsh运行source ./virtualenv/venv/bin/activate && pip install mysql-python django South
,并观察它是否有效。
这不是this之类的重复问题,因为即使我在代码中使用with prefix(
,我也会收到同样的错误。
有什么想法吗?
答案 0 :(得分:3)
将source
替换为/bin/bash/
。这是一个例子:
from fabric.api import *
def init():
local('virtualenv --no-site-packages venv')
venv_command = '/bin/bash venv/bin/activate'
pip_command = 'venv/bin/pip install mysql-python django South'
local(venv_command + ' && ' + pip_command)
仅供参考,对于run/sudo
,最好使用prefix
上下文管理器,例如建议的here。
希望有所帮助。