找不到软件包"rsc.io/quote" [英] cannot find package "rsc.io/quote"

查看:189
本文介绍了找不到软件包"rsc.io/quote"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注本教程( https://golang.org/doc/tutorial/getting -started )开始使用Go,我已经遇到了问题.当我运行以下代码时:

I am following the tutorial (https://golang.org/doc/tutorial/getting-started) to get started using Go and I've already run into a problem. When I run the following code:

package main

import "fmt"

import "rsc.io/quote"

func main() {
    fmt.Println(quote.Go())
}

我在控制台中收到以下错误消息:

I get the following error message in my console:

C:\Users\myname\Documents\Work\GO\hello>go run hello.go
hello.go:7:8: cannot find package "rsc.io/quote" in any of:
        C:\Program Files\Go\src\rsc.io\quote (from $GOROOT)
        C:\Users\myname\go\src\rsc.io\quote (from $GOPATH)

我想这是我安装Go的方式/位置的问题,请问有人可以帮忙吗?

I am guessing this is an issue with how/ where I installed Go, can anybody shed some light please?

谢谢

推荐答案

具有模块支持的go工具会自动下载并安装依赖项.但是要使其正常工作,必须初始化模块.

The go tool with module support automatically downloads and installs dependencies. But for it to work, you must initialize your module.

仅将源保存在.go文件中并与go run hello.go一起运行是不够的,go.mod文件必须存在.

It's not enough to save the source in a .go file and run with go run hello.go, a go.mod file must exist.

要初始化模块,请按照本教程中的指示进行操作:

To init your module, do as indicated in the tutorial:

go mod init hello

输出应为:

go: creating new go.mod: module hello

所以下次运行

go run hello.go

将自动下载rsc.io/quote软件包:

go: finding module for package rsc.io/quote
go: found rsc.io/quote in rsc.io/quote v1.5.2
Don't communicate by sharing memory, share memory by communicating.

最后一行是成功运行该应用程序的输出.

The last line is the output of successfully running the app.

这篇关于找不到软件包"rsc.io/quote"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆