gpt4 book ai didi

Go 包不在 $GOROOT 中

转载 作者:行者123 更新时间:2023-12-02 16:07:26 25 4
gpt4 key购买 nike

我正在使用以下 Go 模块构建应用程序:

github.com/martinlindhe/unit

现在,Go 代码非常简单;我只是想为实际工作设置环境:

import(
"fmt"
"unit"

)

foo := unit.FromFahrenheit(100)
fmt.Println("100 fahrenheit in celsius = ", foo.Celsius())

在 go.mod 中:


go 1.17

require github.com/martinlindhe/unit v0.0.0-20210313160520-19b60e03648d

执行 go buildgo get 结果:

包单元不在 GOROOT (/usr/local/Cellar/go/1.17/libexec/src/unit)

运行 go mod download 执行没有错误。 go.sum 文件似乎是正确的,所有必要的依赖项都存在。

环境是最新版本的VS Code,在MacOS Big Sur 11.5.2上通过homebrew安装Go

肯定有一些明显的东西是我遗漏的。我编写的其他应用程序没有遇到过这个问题。

最佳答案

导入路径不对。 Playground .

package main

import (
"fmt"
"github.com/martinlindhe/unit"
)

func main() {
foo := unit.FromFahrenheit(100)
fmt.Println("100 fahrenheit in celsius = ", foo.Celsius())

}

关于Go 包不在 $GOROOT 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69023352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com