【问题标题】:Installing external packages in golang在 golang 中安装外部包
【发布时间】:2018-10-31 06:36:27
【问题描述】:

我正在尝试在我的 golang 代码中导入一个包。但它向我显示了这个错误:

在以下任何一个中都找不到包“github.com/mattbaird/jsonpatch”: /opt/go/src/github.com/mattbaird/jsonpatch(来自 $GOROOT) /chaincode/input/src/github.com/mattbaird/jsonpatch(来自 $GOPATH) /opt/gopath/src/github.com/mattbaird/jsonpatch"

有人可以帮我解决这个问题吗?

谢谢。

【问题讨论】:

标签: go github


【解决方案1】:

重新检查您的环境变量($GOPATH$GOROOT)。

您面临的问题是,您的代码正在/opt/go/src/github.com//chaincode/input/src/github.com//opt/gopath/src/github.com/ 目录中搜索包github.com/mattbaird/jsonpatch。但是你已经将包安装在C:\Users\xyz\go\src\github.com目录下。

【讨论】:

  • 非常感谢您澄清这一点。你能告诉我如何访问 /opt/ 文件夹
  • 我使用的是windows系统,我认为/usr/local/和/opt/一样
【解决方案2】:

确保您的$GOPATH 环境变量设置正确。

然后仔细检查软件包是否已安装,如果没有,您需要安装可以使用的软件包。

go get github.com/mattbaird/jsonpatch

【讨论】:

  • 是的,我已经处理好了。我已将 GOROOT 设置为 'C:\Go\' 我还将 GOPATH 设置为我编写 gocode 的位置。我已经在 'C:\Users\xyz\src' 位置的 'C:\Go\' 文件夹之外编写了我的 Gocode。所以 GOAPTH 设置为相同的值。但它仍然显示相同的错误。
  • 软件包已正确安装在 go 文件夹中的“C:\Users\xyz\go\src\github.com”位置。
猜你喜欢
  • 2011-08-17
  • 2021-06-03
  • 2016-02-05
  • 2020-07-02
  • 2014-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多