unable to generate proto go files

Viewed 25

I am having an issue generating proto files in go. I have installed it via homebrew

brew install protobuf

output:

Warning: protobuf 21.6 already installed

I have even tried

brew update protobuf

oddly when I create the version

-> % protoc --version
zsh: command not found: protoc

makefile

    .PHONY: proto-gen
    proto-gen:
        protoc -I=grpc/api grpc/api/book.proto --go-grpc_out=. grpc/api/*.proto

file structure

grpc--
      |
       api
          |
          books.proto
Makefile

but when I run the make file I get

/bin/sh: protoc: command not found
make: *** [proto-gen] Error 127
protoc -I=grpc/api grpc/api/book.proto --go-grpc_out=. grpc/api/*.proto

proto file

syntax = "proto3";

import "google/protobuf/any.proto";

service BookService {
  rpc GetBooks(GetBooksRequest) returns (stream GetBooksRequest){}
  rpc GetBookByBookId(GetBookByIdRequest) returns (GetBookByIdResponse){}
}

message GetBooksRequest {

}

message GetBooksResponse {

}

message GetBookByIdRequest {
  string id = 1;
}

message GetBookByIdResponse {

}

UPDATE #1:

odd the command will not work so I decided to try a docker image

Makefile

.PHONY: proto-docker
proto-docker: ## Generate protobuf code
    docker run --rm -v $(pwd):/mnt memominsk/protobuf-alpine:latest --go_out=pkg/api  ${CURDIR}/proto/api/book.proto

ERROR

docker run --rm -v :/mnt memominsk/protobuf-alpine:latest --go_out=pkg/api  /Users/tyeman/programming/codecamp/proto/api/book.proto
Could not make proto path relative: /Users/tyeman/programming/codecamp/proto/api/book.proto: No such file or directory
make: *** [proto-docker] Error 1

However that path 100% exists.

Update #2

I had to update xcode to get it to work correctly but it still cannot generate the files.

both of these make commands produce errors

.PHONY: proto
proto: ## Generate protobuf code
    mkdir -p pkg/api
# Compile proto files inside the project.
    protoc -I=proto/api \
        --go_out=. \
        --go-grpc_out=pkg/api \
        --proto_path=/Users/tyeman/programming/codecamp/proto/api/book.proto

.PHONY: proto-docker
proto-docker: ## Generate protobuf code
    docker run --rm -v $(pwd):/mnt memominsk/protobuf-alpine:latest --go_out=pkg/api ${PROJ_PATH}/proto/api/book.proto

the docker command produces

Could not make proto path relative: /Users/tyeman/programming/codecamp/proto/api/book.proto: No such file or directory
make: *** [proto-docker] Error 1

and the other one gives me

Missing input file.
make: *** [proto] Error 1

I am still not sure why I am getting these errors.

1 Answers

Head to the protoc releases page and download the protoc-3.4.0-win32.zip, extract it, and you will find protoc.exe in the bin directory.

Move this to models/research folder tensorflow model project

Next,you can use the protoc command like

protoc object_detection/protos/*.proto --python_out=.

Related