user3665510
user3665510

Reputation: 41

visual studio code golang package import problem

could someone enlighten me on how to get simple import statements in vsc to work for an example main.go file I borrowed from somewhere? The following observations apply:

  1. go version go1.17.2 windows/amd64;
  2. I can get this program to run (using modules) without any problems;
  3. The imports in my main program are for fyne like e.g. "fyne.io/fyne/v2/app" etc.;
  4. $GOROOT points to something like C:\Program files\Go.. ;
  5. $GOPATH points to C:\Users\xyz\go.... ;
  6. My current source code is located under $GOPATH\src... but can be moved somewhere else if needed;
  7. In my source subdirectory there is a main.go and I added a module file as follows: go mod init main & go mod tidy this results in the following output : go: finding module for package fyne.io/fyne/v2/app go: finding module for package fyne.io/fyne/v2 go: finding module for package fyne.io/fyne/v2/container go: finding module for package fyne.io/fyne/v2/canvas go: found fyne.io/fyne/v2 in fyne.io/fyne/v2 v2.1.2 go: found fyne.io/fyne/v2/app in fyne.io/fyne/v2 v2.1.2 go: found fyne.io/fyne/v2/canvas in fyne.io/fyne/v2 v2.1.2 go: found fyne.io/fyne/v2/container in fyne.io/fyne/v2 v2.1.2

So it seems that everything thats needed is there and I can subsequently run the program.

  1. However when displaying my main.go source in vsc (1.63.0) it complains about not being able to find(import) any of the required fyne packages/imports. It lists that it looks in the \src subdirectories of both $GOROOT and $GOPATH but can't find anything. This is actually correct because there is nothing there. The closest I can find are fyne packages located under C:\Users\xyz\go\pkg\mod\fyne.io\fyne...

Looked at all kinds of documentation but have no clue of whats exactly the problem and how to solve this.

Thanks in advance
Peter

Upvotes: 0

Views: 1055

Answers (1)

Wolfgang
Wolfgang

Reputation: 1398

Your dependencies should be located in the right place, i.e. where the build tool, in this case vsc is expecting them. So move them there, and set your GOPATH correctly as explained here: https://www.c-sharpcorner.com/article/how-to-setup-golang-with-vscode/

Upvotes: 0

Related Questions