据我所知,“当前”的最佳实践是:
- 点管理依赖
- setup.py执行构建
执行“ pip install”。几乎等同于执行“ pip install -r requirements.txt” +“ python setup.py
build” +“ python setup.py install”。
这是一个自定义命令,可从原始文件生成python源:
class GrpcTool (Command): def initialize_options(self): pass def finalize_options(self): pass def run(self): import grpc_tools.protoc proto_include = pkg_resources.resource_filename('grpc_tools', '_proto') grpc_tools.protoc.main([ 'grpc_tools.protoc', '-I{}'.format(proto_include), '--python_out=SOME_PATH/', '--grpc_python_out=SOME_PATH/', 'SOME_PROTO.proto' ])通过定制build_py命令调用,如下所示:
class BuildPyCommand (build_py): def run(self): self.run_command('grpc') super(BuildPyCommand, self).run()注意导入 内部 的run方法。在安装要求之前和之后,pip似乎多次运行setup.py。因此,如果将导入放在文件之上,则构建将失败。



