关于使用Python脚本自动编译proto文件生成xxx_pb2.py的方法 一、单个文件 使用Python的subprocess模块来调用protoc命令,并在命令行中指定参数。下面是一个调用protoc生成example_pb2.py的示例代码: import subprocess proto_file = "example.proto" output_dir = "." # 调用 protoc 命令 subprocess.call([