英文:
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 build
或go 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())
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论