title: Go build cannot find package
body: <h1>Problem</h1>
  
  <p>I haven't been able to find a solution to this by looking at related questions. I can't tell what makes my Go environment different from the canonical setup.</p>
  
  <p><code>go env</code> returns</p>
  
  <pre><code>GOROOT="/usr/lib/go"
  GOBIN=""
  GOARCH="386"
  GOCHAR="8"
  GOOS="linux"
  GOEXE=""
  GOHOSTARCH="386"
  GOHOSTOS="linux"
  GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
  GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
  CGO_ENABLED="1"
  </code></pre>
  
  <p><code>tree $GOPATH</code> returns</p>
  
  <pre><code>/home/USER/go
  ├── bin
  ├── pkg
  │   └── linux_386
  │       └── bitbucket.org
  │           └── USER-NAME
  │               └── PROJECT
  │                   └── my_package.a
  └── src
      └── bitbucket.org
          └── USER-NAME
              └── PROJECT
                  ├── main
                  │   ├── main.go
                  └── my_package
                      └── my_package.go
  </code></pre>
  
  <p>(ALL-CAPS are substitutions)</p>
  
  <p>main.go contains</p>
  
  <pre><code>package main
  
  import (
          "bitbucket.org/USER-NAME/PROJECT/my_package"
  )
  
  func main() {
          my_package.Foo()
  }
  </code></pre>
  
  <p>Calling <code>go build</code> in the <code>main</code> directory returns <code>import "my_package": cannot find package</code></p>
  
  <p>Volker pointed out that <code>go env</code> should have returned a <code>GOPATH</code> entry as well. <a href="http://golang.org/src/cmd/go/env.go" rel="nofollow">The source of the env command</a> corroborates that. However, running <code>echo $GOPATH</code> in bash or <code>os.Getenv("GOPATH")</code> in Go both return <code>\home\USER\go</code>. I'm not sure why the same isn't returned by <code>go env</code>.</p>
  
  <h1>Solution</h1>
  
  <p>I was running Go 1.0 when I was having this issue. The problem disappeared when I upgraded to Go 1.2.1.</p>