简体   繁体   中英

Issues in compiling grpc python code from protos

I am using python version 2.7.6 and grpcio version 1.12.0. I have a proto with message definition containing a enum something like this

enum Test {
    first 0;
    reserved 1;
    second 2;
}

Now when I try to compile using command

python -m grpc_tools.protoc -I./ --python_out=. --grpc_python_out=. mydata.proto

I get an error message something like this

Missing numeric value for enum constant

Is it because of the python and grpcio version?

Your message definition uses invalid syntax. Perhaps you intend something like:

enum Test {
    first = 0;
    reserved 1;
    second = 2;
}

Note the added equals signs. This enum specifies two values, first and second , and reserves "1" for future use.

Reference:https://developers.google.com/protocol-buffers/docs/proto3#enum

I'll throw an answer on here because this was the top Stack Overflow post when I was getting the same error Missing numeric value for enum constant when I had reserved fields in an enum.

I was trying to compile the headers for C++ and downloaded the protoc compiler that was linked fromthe protocol buffers tutorial . Running Ubuntu 18.04 and just could not get the thing to recognize the reserved fields.

This Github issue was mentioning that I needed to have version 3.6, but I just downloaded and made 3.20 and it still wasn't working.

The issue for me was that I didn't follow the documentation all the way. There is a Readme in the protobuf repo that says, in part:

To build and install the C++ Protocol Buffer runtime and the Protocol Buffer compiler (protoc) execute the following:

 ./configure make -j$(nproc) # $(nproc) ensures it uses all cores for compilation make check sudo make install sudo ldconfig # refresh shared library cache.

I did the ./configure , make , and make check steps, but then forgot to sudo make install or sudo ldconfig . Once I did that, I got the correct version when I ran protoc --version .

I did have an issue where I did all this, got the right version, and then still had errors, but the terminal window I was using had been opened before I installed. Once I ran source ~/.bashrc I was able to build the messages without any issues!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM