我开始使用 Python Invoke
from invoke import task
@task
def build():
    print("Building!")
预期的产出是
$ invoke build
Building!
但是,我的输出是
$ invoke build
Can't find any collection named 'tasks'!
我不知道为什么.
令人惊奇的是,一旦我在virtualenv中调用,那么我可以在没有virtualenv的情况下构建.
> mkvirtualenv myenv
> invoke build
Building!
> deactivate myenv
> invoke build
Building!
我错过了什么?
这个问题与此类似,但并不完全相同。
我安装了python2.7和python3.5。我可以从命令行使用脚本之一运行脚本。我当前的默认“ python”是python2。
我有一个需要运行pyinvoke的python3脚本,该脚本通常是使用invoke <task>命令行中的命令运行的。即使当我设置使用python3的虚拟环境时,invoke仍然使用python2。
我认为关于虚拟环境我缺少什么?
我目前唯一的解决方法是仅为python3安装pyinvoke。然后它将在python3下运行。
有人知道如何设置它以与虚拟环境一起使用吗?
我想在pyinvoke的任务中使用可变数量的参数.像这样:
from invoke import task
@task(help={'out_file:': 'Name of the output file.', 
            'in_files': 'List of the input files.'})
def pdf_combine(out_file, *in_files):
    print( "out = %s" % out_file)
    print( "in = %s" % list(in_files))
以上只是我尝试过的众多变化中的一种,但似乎pyinvoke无法处理可变数量的参数.这是真的?
上面的代码导致了
$ invoke pdf_combine -o binder.pdf -i test.pdf test1.pdf
No idea what '-i' is!
类似的,如果我定义pdf_combine(out_file,in_file),在in_file之前没有星号
$ invoke pdf_combine -o binder.pdf -i test.pdf test1.pdf
No idea what 'test1.pdf' is!
如果我只使用下面的一个in_file调用任务,则运行OK.
$ invoke pdf_combine -o binder.pdf -i test.pdf
out = binder.pdf
in = ['t', 'e', 's', 't', '.', 'p', …pyinvoke支持所谓的“预”任务,必须在运行任务之前执行:
@task(pre=[required_precondition])
def mytask(c, param1=False):
    pass
是否可以向“pre”任务添加一个条件(即仅当 param1 为 True 时才运行“required_precondition”)?
使用invoke,如何更改run呼叫操作的目录?
在Fabric中,人们会
from fabric.context_managers import lcd
with lcd('foo'):
   local('do')
do在foo目录中运行,但我在pyinvoke中找不到类似的导入.