英文:
could not import google.golang.org/grpc (cannot find package "google.golang.org/grpc"
问题
嗨,我用一些go get命令在我的vscode项目中安装了golang grpc。
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
我在vscode中可以构建/运行项目,也可以在命令行中运行,但是自动补全功能报错:
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/john/go/src/google.golang.org/grpc (from $GOPATH))
从我的主目录中查找:
find * -iname google.golang.org
go/src/google.golang.org
go/pkg/mod/google.golang.org
go/pkg/mod/cache/download/google.golang.org
go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/google.golang.org
我的.profile文件底部内容如下:
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:~/go
export GOPATH=/home/john/go
export PATH=$PATH:$GOPATH/bin
我尝试将pkg目录中的源代码复制到src目录中。
英文:
Hi I installed golang grpc in my vscode project with some go get commands,
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
from https://stackoverflow.com/a/62872353/4159198
my project builds/runs inside vscode and on the command line but autocomplete gives me an 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/john/go/src/google.golang.org/grpc (from $GOPATH))
Find from my home directory:
find * -iname google.golang.org
go/src/google.golang.org
go/pkg/mod/google.golang.org
go/pkg/mod/cache/download/google.golang.org
go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/google.golang.org
My .profile bottom,
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:~/go
export GOPATH=/home/john/go
export PATH=$PATH:$GOPATH/bin
I tried copying the source from pkg to src directory.
答案1
得分: 3
尝试在每个要编译的程序上运行"go mod init"命令。
如果有需要导入的包且缺失,会出现一个灯泡图标,你可以点击它自动获取你想要的包。
在你的go.mod文件中会写着
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.25.0 // indirect
英文:
Try to launch go mod init on every program you want to compile.
If there was packages to imported and it missing, there will be a lightbulb icon that you can click on to automatically go get the packages you want
On your go.mod will there written
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.25.0 // indirect
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论