go: go.mod file not found in current directory or any parent directory; see ‘go help modules‘

一、问题描述

执行 main.go 报如下错误

go: go.mod file not found in current directory or any parent directory; see 'go help modules'

二、解决办法

在项目目录下打开cmd窗口,根据需要选择执行下面的命令。

1)开启 go modules 功能,命令行输入

go env -w GO111MODULE=on

2)在该项目目录下,初始化Go moudle,运行下面命令

go mod init
或者
go mod init xxx               // xxx 代表 目录名称

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xiaojin21cen/article/details/124610464