Go包不在$GOROOT中

huangapple go评论69阅读模式
英文:

Go package not in $GOROOT

问题

我正在使用以下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会出现以下错误:

package unit is not in GOROOT (/usr/local/Cellar/go/1.17/libexec/src/unit)

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

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

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

英文:

I'm using the following Go module to build an application:

github.com/martinlindhe/unit

Right now, the Go code is very simple; I'm just trying to get the environment set up for the real work:

import(
	"fmt"
	"unit"
	
)

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

In go.mod:


go 1.17

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

Executing either go build or go get results in:

package unit is not in GOROOT (/usr/local/Cellar/go/1.17/libexec/src/unit)

Running go mod download executes without error. The go.sum file seems to be correct, all the necessary dependencies exist.

The environment is the latest version of VS Code, Go installed via homebrew on MacOS Big Sur 11.5.2

There must be something obvious I'm missing. I've not had this problem with other apps I've written.

答案1

得分: 6

导入路径不正确。Playground.

package main

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

func main() {
        foo := unit.FromFahrenheit(100)
        fmt.Println("100华氏度等于摄氏度:", foo.Celsius())

}

英文:

The import path is not right. Playground.

package main

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

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

}

huangapple
  • 本文由 发表于 2021年9月2日 10:21:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/69023352.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定