问题描述
复制步骤:
- 在Linux环境中,在桌面上创建一个名为"fab"的文件夹
- 仅供参考,我正在使用zsh
- 从CD到
~/Desktop/fab
-
运行在您的./fab目录中制作的
fabfile.py
,方法是发出fab init
:
- In a linux environment, create a folder on your desktop called 'fab'
- FYI, I'm using zsh
- cd to
~/Desktop/fab
Run this
fabfile.py
made in your ./fab dir by issuingfab 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')
出现此错误:
Get this error:
➜ 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
,并观察它是否有效.
Run source ./virtualenv/venv/bin/activate && pip install mysql-python django South
from zsh, and observe that it works.
这不是重复的问题,例如此,因为即使在代码中使用with prefix(
,我也遇到相同的错误.
This is not a duplicate question of something like this, as I am getting the same error even if I use a with prefix(
in my code.
有什么想法吗?
推荐答案
将source
替换为/bin/bash/
.这是一个示例:
Replace source
with /bin/bash/
. Here's an example:
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
上下文管理器,如建议的此处.
FYI, for run/sudo
it's better to use prefix
context manager, like suggested here.
希望有帮助.
这篇关于使Python虚拟环境,Fabric和Sudo协同工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!