简体   繁体   English

go:找到模块但不包含 package

[英]go: module found but does not contain package

I am trying to install the net package for go but get "does not contain package error".我正在尝试为 go 安装网络 package 但得到“不包含 package 错误”。

Terminal screenshot:终端截图:

在此处输入图像描述

I have consulted: go module @latest found but does not contain package but none of the solutions seem to work for me.我已经咨询过: go 模块 @latest found 但不包含 package但似乎没有一个解决方案适合我。

I am using go version go1.18.5 linux/amd64我正在使用 go 版本go1.18.5 linux/amd64

go get -u golang.org/x/net

go install used for executable packages go 安装用于可执行包

You have to initialize your module with go mod init in the project root directory您必须在项目根目录中使用go mod init初始化您的模块

For local codebase对于本地代码库

go mod init test

OR for hosted codebase eg github repo: test , github user: radiant或用于托管代码库,例如 github 存储库:测试,github 用户:辐射

go mod init github.com/radiant/test

It will produce a go.mod file.它将生成一个go.mod文件。

Then you can get the required package as:然后您可以获得所需的 package 为:

go get golang.org/x/net
go mod tidy

Then import and use the net packages.然后导入并使用网络包。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找到模块 XXX,但不包含 package XXX - Module XXX found, but does not contain package XXX 找不到模块:包路径。 不从包中导出 - Module not found: Package path . is not exported from package Firebase 错误:找不到模块:错误:包路径。 不从包中导出 - Firebase Error : Module not found: Error: Package path . is not exported from package `Firebase` package 已成功找到。 但是,这个 package 本身指定了一个无法解析的“主”模块字段 - `Firebase` package was successfully found. However, this package itself specifies a `main` module field that could not be resolved 为什么将 --package-path 设置为本地目录会在 gcloud 中出现 python not found 错误? - Why does setting --package-path to a local directory give python not found error in gcloud? “UnityWebRequest”不包含“结果”的定义 - 'UnityWebRequest' does not contain a definition for 'result' go 模块 - 替换不起作用 - 没有版本的替换模块必须是目录路径(根或以 - go modules - replace does not work - replacement module without version must be directory path (rooted or starting with 找不到 Notifee 本机模块 - Notifee native module not found Go 模块即使在从 GitHub 删除模块 repo 后仍然可用 - Go module is usable even after deleting the module repo from GitHub SendGrid 模板不包含必需的占位符 - SendGrid Template does not contain required placeholders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM