Camuslu
Camuslu

Reputation: 123

protobuf: .proto file not under source directory

I'm new to protobuf. Following the official tutorial https://developers.google.com/protocol-buffers/docs/gotutorial, I downloaded the latest release and tried to run the example examples/addressbook.proto

Inside addressbook.proto, there is a line import "google/protobuf/timestamp.proto";,

so one would need to provide a source directory (the -I=) so as to import this.

My problem is that, in the downloaded release, I have addressbook.proto under examples while the needed google/protobuf/timestamp.proto is under src

When I do

protoc examples/addressbook.proto --python_out=. -I=src

I get an error

examples/addressbook.proto: File does not reside within any path specified using --proto_path (or -I)

I tried playing around with using --proto_path and got the same error.

The issue is solved when I manually move the addresbook.proto under src, so that the needed package and the .proto are both under the same dir (specified by -I=src).

However, I wonder if there is a solution when the .proto file and the other to-be-imported packages are under different directories.

Upvotes: 0

Views: 2389

Answers (1)

jpa
jpa

Reputation: 12156

You need:

protoc examples/addressbook.proto --python_out=. -I=src -I=examples

When protoc is installed system-wide, it usually has timestamp.proto in the default include path and -I doesn't have to be specified. But when building from the source folder directly it doesn't know the path automatically.

Upvotes: 1

Related Questions