go install 报错 cannot find package“xxx/xxx“

问题:

go install安装包的时候,如果本地环境没有对应的包,就会报错
cannot find package“xxx/xxx“。

解决:

如果可以翻墙的话可以执行go get来获取对应的包。

mkdir -p $GOPATH/src/google.golang.org/
cd $GOPATH/src/google.golang.org/
go get google.golang.org/grpc

没有工具的话,就需要把对应的包换成GitHub上的。但是从GitHub上git clone又很慢,这里有2种解决方法:
1.把GitHub的源换成Gitee
2.安装GitHub加速插件(推荐),安装后会有一个加速链接。
比如grpc:
file

cd $GOPATH/src/google.golang.org/
git clone https://github.91chi.fun/https://github.com/grpc/grpc-go.git grpc

附录

这里列举我在go install时报错缺少的包的下载链接。需要先创建对应目录,然后进行下载。

#google.golang.org/grpc
git clone https://github.91chi.fun/https://github.com/grpc/grpc-go.git grpc
#google.golang.org/genproto
git clone https://github.91chi.fun/https://github.com/googleapis/go-genproto.git genproto
#google.golang.org/protobuf
git clone https://github.91chi.fun/https://github.com/gogo/protobuf.git
#github.com/coreos
git clone https://github.91chi.fun/https://github.com/coreos/go-semver.git
#github.com/dustin
git clone https://github.91chi.fun/https://github.com/dustin/go-humanize.git
#github.com/golang/protobuf
git clone https://github.91chi.fun/https://github.com/golang/protobuf.git
#github.com/beorn7
git clone https://github.91chi.fun/https://github.com/beorn7/perks.git
#github.com/cespare
git clone https://github.91chi.fun/https://github.com/cespare/xxhash.git
#github.com/gogo
git clone https://github.91chi.fun/https://github.com/gogo/protobuf.git
#github.com/matttproud
git clone https://github.91chi.fun/https://github.com/matttproud/golang_protobuf_extensions.git
#github.com/prometheus
git clone https://github.91chi.fun/https://github.com/prometheus/client_model.git
git clone https://github.91chi.fun/https://github.com/prometheus/client_golang.git
git clone https://github.91chi.fun/https://github.com/prometheus/common.git
git clone https://github.91chi.fun/https://github.com/prometheus/procfs.git
#go.etcd.io
git clone https://github.91chi.fun/https://github.com/etcd-io/etcd.git(这里装好还会报错,需要创建v3目录,注意包的路径)
#go.uber.org/atomic
git clone https://github.91chi.fun/https://github.com/uber-go/atomic.git
#go.uber.org/multierr
git clone https://github.91chi.fun/https://github.com/uber-go/multierr.git
#go.uber.org/zap
git clone https://github.91chi.fun/https://github.com/uber-go/zap.git
#golang.org/x
git clone https://github.91chi.fun/https://github.com/golang/text.git
git clone https://github.com/golang/sys.git
git clone https://github.91chi.fun/https://github.com/golang/net.git net
Cannot find module是一个常见的错误,通常表示在项目中找不到所需的模块。解决这个问题的方法可以根据具体情况而定。 一种可能的解决方法是检查项目的package.json文件,并确保所需的模块(例如vue)已经被正确地列在dependencies中。如果没有,可以使用cnpm install命令安装该模块。 另一种解决方法是删除项目中的node_modules文件夹和package-lock.json文件,并运行npm install命令重新安装依赖项。这样可以解决潜在的依赖关系冲突或缓存问题。 总结起来,解决Cannot find module错误的步骤可以包括: 1. 检查package.json文件,确保所需的模块已经被正确地列在dependencies中,并使用cnpm install安装缺少的模块。 2. 删除项目中的node_modules文件夹和package-lock.json文件,并运行npm install重新安装依赖项。 请根据具体情况选择适合的解决方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [vue项目Error: Cannot find module ‘xxx’类报错的解决方法](https://blog.csdn.net/loveLifeLoveCoding/article/details/121789466)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Cannot find module 'lodash'](https://blog.csdn.net/qq_43702430/article/details/103710447)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柠是柠檬的檬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值