Go 包不在 $GOROOT 中

All*_*her 2 go

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

github.com/martinlindhe/unit

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

import(
    "fmt"
    "unit"
    
)

foo := unit.FromFahrenheit(100)
fmt.Println("100 fahrenheit in celsius = ", foo.Celsius())
Run Code Online (Sandbox Code Playgroud)

在 go.mod 中:


go 1.17

require github.com/martinlindhe/unit v0.0.0-20210313160520-19b60e03648d
Run Code Online (Sandbox Code Playgroud)

执行go buildorgo get会导致:

package unit is not in 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

我一定缺少一些明显的东西。我编写的其他应用程序没有遇到此问题。

Sha*_*shi 6

导入路径不对。游乐场。

package main

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

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

}

Run Code Online (Sandbox Code Playgroud)