When I try to import the grpc package I get the following error:
could not import google.golang.org/grpc (cannot find package "google.golang.org/grpc" in any of
/usr/local/go/src/google.golang.org/grpc (from $GOROOT)
/home/ansh/Go/src/google.golang.org/grpc (from $GOPATH))
This is my gopath (incase it helps):
export GOPATH="$HOME/Go"
export PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
I did install these two packages:
$ go install google.golang.org/protobuf/cmd/[email protected]
$ go install google.golang.org/grpc/cmd/[email protected]
But it doesnt seem to work
In case you are using go modules, there is no need to set
GOPATHanymore. However ifGOPATHis set and you want to use a package from your project directory you need to setGO111MODULE=off, because by defaultGO111MODULEis set asON. So even if the packagegoogle.golang.org/grpcis in yourGOPATHyou will have to force Go not to use the Go modules.So something like this should work in case you are still opting of using
GOPATH.