Go build: “Cannot find package” (even though GOPATH is set)

前端 未结 9 1532
庸人自扰
庸人自扰 2020-12-04 07:35

Even though I have GOPATH properly set, I still can\'t get \"go build\" or \"go run\" to find my own packages. What am I doing wrong?

$ echo $GO         


        
9条回答
  •  广开言路
    2020-12-04 08:15

    To be able to find your project's packages without installing it, (which is common during development), simply append project path to GOPATH.

    • In terminal (Linux):
      First run: GOPATH=$GOPATH:/path/to/project
      Then go run main.go should be able to find packages from the project itself.
      Similar for Mac; for Windows the delimiter is ; not :.
    • In Goland:
      Settings -> Go -> GOPATH, under Project GOPATH, add project path.
      Then Goland should be able to find packages from the project itself during development.

提交回复
热议问题