go
build_error
ai_generated
true
包 example.com/user/project:在任何位置都找不到包 "example.com/user/project": /usr/local/go/src/example.com/user/project(来自 $GOROOT) /home/user/go/src/example.com/user/project(来自 $GOPATH)
package example.com/user/project: cannot find package "example.com/user/project" in any of: /usr/local/go/src/example.com/user/project (from $GOROOT) /home/user/go/src/example.com/user/project (from $GOPATH)
ID: go/cannot-find-package-in-gopath
80%修复率
87%置信度
0证据数
2024-05-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.0 | active | — | — | — |
| 1.1 | active | — | — | — |
| 1.2 | active | — | — | — |
| 1.3 | active | — | — | — |
| 1.4 | active | — | — | — |
| 1.5 | active | — | — | — |
| 1.6 | active | — | — | — |
| 1.7 | active | — | — | — |
| 1.8 | active | — | — | — |
| 1.9 | active | — | — | — |
| 1.10 | active | — | — | — |
| 1.11 | active | — | — | — |
| 1.12 | active | — | — | — |
| 1.13 | active | — | — | — |
| 1.14 | active | — | — | — |
| 1.15 | active | — | — | — |
| 1.16 | active | — | — | — |
根因分析
包未位于预期的 GOPATH 或 GOROOT 目录中,通常是因为项目未克隆到正确的 GOPATH 结构中,或者未启用模块。
English
The package is not located in the expected GOPATH or GOROOT directories, often because the project was not cloned into the correct GOPATH structure or modules are not enabled.
解决方案
-
95% 成功率 Enable Go modules and initialize the module
GO111MODULE=on go mod init example.com/user/project
-
85% 成功率 Move the project to the correct GOPATH location
mkdir -p $GOPATH/src/example.com/user && mv /current/project $GOPATH/src/example.com/user/project
无效尝试
常见但无效的做法:
-
Setting GO111MODULE=off and hoping GOPATH resolves
70% 失败
Disabling modules forces GOPATH mode, but if the project is not in the correct GOPATH src directory, it still fails.
-
Copying the project to GOROOT/src
90% 失败
GOROOT is for the standard library; placing user projects there is unsupported and can cause conflicts.