V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
nyxsonsleep
V2EX  ›  Go 编程语言

Go 可以运行, vscode 语法检查提示找不到包

  •  
  •   nyxsonsleep · 2022-08-30 14:36:15 +08:00 · 802 次点击
    这是一个创建于 612 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码块

    package main
    import(
    	"github.com/gocolly/colly/v2"
    	"fmt"
    )
    func main() {
    	// create a new collector
    	c := colly.NewCollector()
    	fmt.Println(c)
    }
    

    运行结果

    Requests made: 0 (0 responses) | Callbacks: OnRequest: 0, OnHTML: 0, OnResponse: 0, OnError: 0
    

    这行"github.com/gocolly/colly/v2"飘红,提示:

    error while importing github.com/gocolly/colly/v2: cannot find package "github.com/saintfish/chardet" in any of

    能用,但是该怎么解决飘红的问题。有两个 gopath ,目前在第二个 gopath 目录下的 src 目录的下级目录中运行,有 go.mod,go.sum 。

    Vegetable
        1
    Vegetable  
       2022-08-30 14:53:30 +08:00
    如果不是什么历史遗留原因的话,还是把项目从 gopath 里边移出来吧,go 都出到 1.19 了,大家可能已经告别 gopath 很久了。
    你这个症状看起来,就是 gopls 并没有找到这个包,但是 go 命令能识别到。看起来是 gopls 去 gopath 里边找了,但是 go 命令能正确识别 go mod 安装的包。

    极大概率可以通过移出来解决问题
    nyxsonsleep
        2
    nyxsonsleep  
    OP
       2022-08-30 15:06:35 +08:00
    @Vegetable 非常感谢,看来是有了 mod 之后不再需要 gopath 了,删除环境变量后正常了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   923 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:49 · PVG 02:49 · LAX 11:49 · JFK 14:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.