Skip to content

Instantly share code, notes, and snippets.

@MarkBennett
Created September 22, 2012 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkBennett/3767324 to your computer and use it in GitHub Desktop.
Save MarkBennett/3767324 to your computer and use it in GitHub Desktop.
Failing to import Go packages

I've just installed Go from the package on the golang site.

When trying to build (or run) import getting an import error, but can't figure out why:

go build world2.go

This produces the error:

# world2.go:3:8: import "world": cannot find package

Running "go env" produces:

GOROOT="/usr/local/go" GOBIN="/usr/local/go/bin" GOARCH="amd64" GOCHAR="6" GOOS="darwin" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common" CGO_ENABLED="1"

This is what my file structure looks like (ala tree):

. ├── world.go └── world2.go

Any tips what I'm doing wrong or next steps?

package world
import "fmt"
func Greeting() {
fmt.Println("Ola!")
}
package main
import "world"
func main() {
world.Greeting()
}
@aa-software2112
Copy link

@dearing thank you so much for this, I have been endlessly searching for how to import a local package! So much fluff on all the other explanations. Bang on!

@dearing
Copy link

dearing commented Nov 9, 2019

@aa-software2112 things have evolved since this discussion but I am happy my 7 year old comments have a net positive. Please read up on modules and vendoring and message me if you think I can help in any way.

@khansalmaan
Copy link

hey , I am using atom ...but still cannot import local packages....can anyone help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment