V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
nyxsonsleep

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

  •  
  •   nyxsonsleep · Aug 30, 2022 · 1323 views
    This topic created in 1340 days ago, the information mentioned may be changed or developed.

    代码块

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

    极大概率可以通过移出来解决问题
    nyxsonsleep
        2
    nyxsonsleep  
    OP
       Aug 30, 2022
    @Vegetable 非常感谢,看来是有了 mod 之后不再需要 gopath 了,删除环境变量后正常了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2516 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:51 · PVG 15:51 · LAX 00:51 · JFK 03:51
    ♥ Do have faith in what you're doing.