1.windows下安装
1.从官网下载源码包解压进入vsproject,使用visual studio 打开解决方案,选择protoc生成解决方案会在Debug目录下生成protoc.exe
2.不用源码包安装,可以直接在官网下载protoc.exe
3.设置环境变量D:\
4.进入python目录 执行python setup.py build 然后执行python setup.py install (readme说明里先执行python setup.py test 后执行python setup.py install )
2.使用
1.编写proto文件
package tutorial;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
message AddressBook {
repeated Person person = 1;
}
2.使用protoc.exe 生成py文件
protoc -I=$SRC_DIR --python