为什么在尝试 运行 fab 模块时出现语法错误?

Why do I get a syntax error when trying to run a fab module?

我是第一次尝试 fabric,我正在尝试 运行 他们文档中的 hello world 示例: http://docs.fabfile.org/en/1.14/tutorial.html

我创建了一个名为 fabfile.py 的本地文件,其中包含以下代码行:

def hello():
   print("Hello world!")

现在我尝试在 python 解释器中 运行 它:

> >>> import fabric
> >>> import fabfile
> >>> fab hello   File "<stdin>", line 1
>     fab hello
>             ^ SyntaxError: invalid syntax
> >>> from fabfile import hello

'from fabfile import hello' 有效,所以它必须看到文件和 hello 函数,因为如果我尝试对垃圾关键字执行相同操作,它会出错。但是,然后我尝试使用 'fab function' 语法 运行 代码,它会抛出 'invalid syntax' 错误。

你能告诉我我做错了什么吗?

编辑: 如果我直接在终端中尝试 运行ning 它也不起作用

[user@host folder]$ bash
[user@host folder]$ fab hello
No idea what 'hello' is!
[user@host folder]$ 
[user@host folder]$ ls
fabfile.py  fabfile.pyc  test-connect.py  TST_SYBASE.txt

首先是 FABRIC 的文档已过时

This is an open issue on git.

fabfile.py 需要有正确的装饰器:

from fabric import task

@task
def hello(ctx):
  print("Hello World")

其次

文档显示 fab hello 需要在更高级别执行,在 shell 中,例如 bash

确保您位于包含结构文件的 pwd 中。

运行 fab hello.

这应该是这样的:

Twoodys-MacBook-Air:fabQ twoody$ ls
fabfile.py
Twoodys-MacBook-Air:fabQ twoody$ fab hello
Hello World
Twoodys-MacBook-Air:fabQ twoody$