How can I fix the Go error that appears after restarting the terminal that no downloaded packages were found?

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

How can I fix the Go error that appears after restarting the terminal that no downloaded packages were found?

问题

你的问题是关于在重新打开终端后运行Go程序时出现错误的情况。错误信息显示找不到github.com/labstack/echo/v4包。你已经检查了计算机上的路径,发现存在C:\Users\lol20\go\src\github.com\labstack\echo路径,但没有C:\Users\lol20\go\src\github.com\labstack\echo\v4路径。你认为这可能是问题所在,因为错误信息表明在路径C:\Users\lol20\go\src\github.com\labstack\echo\v4中进行了搜索。

这个问题可能是由于缺少依赖包导致的。你可以尝试使用以下命令来获取缺失的依赖包:

go get -u github.com/labstack/echo/v4

这将下载并安装github.com/labstack/echo/v4包及其依赖项。

如果下载依赖包时遇到问题,可能是由于网络连接或代理设置的原因。你可以尝试使用代理或更改网络设置来解决此问题。

另外,请确保你的Go环境变量配置正确,并且GOPATHGOROOT设置正确。你可以使用以下命令来检查它们的值:

go env GOPATH
go env GOROOT

确保这些路径与你的实际设置相匹配。

如果问题仍然存在,请提供更多详细信息,例如操作系统、Go版本和其他相关配置,以便更好地帮助你解决问题。

英文:

Wrote a simple program for the test:

package main
import (
    "fmt"
	"github.com/labstack/echo/v4"
)
func main() {
	e := echo.New()	
	fmt.Printf("YEEEEEEES!")
	e.Logger.Fatal(e.Start(":1323"))
}

And when go run main.go it prints YEEEEEEES! and starts the server :1323.

But after restarting (close and reopen) the terminal (Bach) and re-entering (in the same path) the same command go run main.go already produces an error:

main.go:4:2: cannot find package "github.com/labstack/echo/v4" in any of: 
        C:\Program Files\Go\src\github.com\labstack\echo\v4 (from $GOROOT)
        C:\Users\lol20\go\src\github.com\labstack\echo\v4 (from $GOPATH) 

Assumed that the problem could be in Echo, but with Iris the situation was the same.

Checked, the computer has a path C:\Users\lol20\go\src\github.com\labstack\echo, but no C:\Users\lol20\go\src\github.com\labstack\echo\v4 (difference in \v4 at the end). I suppose this is the problem, because from the error it is clear that the search is performed in the path C:\Users\lol20\go\src\github.com\labstack\echo\v4.

Please tell me what is the problem and how to fix it(

答案1

得分: 4

尝试按照以下方式切换 GO111MODULE 的值为 "on"go env -w GO111MODULE=on(使用 export GO111MODULE="on" 只在 shell 环境改变之前有效(在重新启动终端之前))。

英文:

Try switching GO111MODULE="on" as follows: go env -w GO111MODULE=on (switching with export GO111MODULE="on" only works until the shell environment changes (before restarting the terminal))

huangapple
  • 本文由 发表于 2022年8月6日 17:25:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/73258610.html
匿名

发表评论

匿名网友

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

确定