Go 'Can't Find Import' - go

I'm attempting to incorporate Heroku's log-shuttle library (https://github.com/heroku/log-shuttle) into a Go project I'm working on. The tool is primarily designed to be run as an independent binary, but I'm hoping to integrate it in a different way in my tool.
So I get the library:
$ go get github.com/heroku/log-shuttle
$ ls $GOPATH/src/github.com/heroku/log-shuttle/
batcher.go Godeps ...
...
which returns successfully. Then I try to import the library:
package myPackage
import (
"github.com/heroku/log-shuttle"
"fmt"
"log"
)
...
Great. But now I go to go build and...
$ go build
# github.com/<my project>
logWriter/log_shuttle_writer.go:5: can't find import: "github.com/heroku/log-shuttle"
I have my GOPATH set correctly (I believe):
$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jeff/go/"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
And the package is installed and built, but it doesn't want to import. As you can see, there are non non-ASCII chars in the package path (though the hyphen is non-alpha-numeric), and I can't find any more info about what could be causing this problem.
Not sure how it would matter, but I am using godep to try to manage my dependencies.
Thanks in advance.

github.com/heroku/log-shuttle is a main package, not an importable library, meaning it's meant to be compiled and run as a binary.

Related

How to deal with "import cycle not allowed" while trying to install gonum?

I'd like to use the gonum libraries for go in order to experiment with some neural network stuff but I cannot go past the install process...
I'm running the command found on the official gonum website :
go get -u -t gonum.org/v1/gonum/...
But it gives me :
import cycle not allowed
package gonum.org/v1/gonum
imports runtime
imports internal/bytealg
imports internal/cpu
imports runtime
Do you know what could be a reason for such a problem?
In case you need my go env in order to help me out, here it is :
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/me/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
I'm running go 1.6.2.
As Adrian told in the comments, the issue was that the go version I was running was too old for gonum to install correctly. This was due to the fact that the go-golang package installed on my computer via apt-get was giving me the 1.6 version of go. By removing the package and making sure I had a recent go release installed on my computer I managed to install gonum.

Go package imports self, and can't find itself in it the GOPATH

Every once in awhile, I'll use a go package that has a go get like : go get github.com/<user>/aRepo and in its own import statement have import "github.com/<user>/aRepo". So it imports itself using a the "go gettable" path. Sometimes this works fine; however, sometimes I get
package github.com/<user>/aRepo
imports github.com/<user>/aRepo
imports github.com/<user>/aRepo: cannot find package "github.com/<user>/aRepo" in any of:
/usr/local/go/src/github.com/<user>/aRepo (from $GOROOT)
/home/me/go/src/github.com/<user>/aRepo (from $GOPATH)
I set my GOPATH with:
export GOPATH=$GOPATH:/home/me/go:`godep path`
It's very unclear as to why this would happen, any ideas as to why?
EDIT
my go env:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=":/home/vagrant/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
So it turns out it was a permissions issue since I was using a vagrant box with a synced folder, vagrant set the entire path that synced folder created as 744 root:root. Therefore, I could not write to that folder as a non-root user, so that error message is actually coming from godep trying to install itself and not finding its src.

Go lang installation issues with ./make.bash ubuntu->windows

I have tried to search and found a lot of topics which are related to my problem, but none of them I could follow to success.
I can go run and go get with no issues, but I need to compile into windows and there I have problems please see bellow
mikhail#mikhail-desktop:/usr/lib/go/src$ sudo ./make.bash
# Building C bootstrap tool.
cmd/dist
go tool dist: $GOROOT is not set correctly or not exported
GOROOT=/usr/share/go
/usr/share/go/include/u.h does not exist
mikhail#mikhail-desktop:/usr/lib/go/src$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mikhail/Documents/FL/0go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
mikhail#mikhail-desktop:/usr/lib/go/src$
By some reasons it thinks the GOROOT is /usr/share/go while it actually /usr/lib/go
sudo can clean environment variables, to check if that is the case here, run sudo $(which go) env and check if the output is what you expect. If not, you can keep the enviroment of your user by using the -E flag: sudo -E ./make.bash.
I think it somehow connected to Debian/Ubuntu thing. I seen such issues but related to 0.9. version.
I have installed go from source into ~/go and then everything went quite OK, now I can compile to windows from ubuntu with help Introduction to cross compilation with go and LiteIDE.

go install: no install location for directory outside GOPATH

I installed the Go, then added path requirements to my .bash_profile:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
I then setup the correct folders:
I also created a projected called tire.
The contents for main.go are simply:
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
I always get the following error when I try to run go install:
go install: no install location for directory /Users/Daryl/go/src/tire outside GOPATH
Here's what I get when I run go env:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/daryl/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Any help would be appreciated.
When you run go install Go looks for $GOBIN env variable path. Either you need to set your $GOBIN to $GOPATH/bin
$ export GOBIN=$GOPATH/bin
and/or add $GOBIN to your OS search path
$ export PATH=$PATH:$GOBIN
To use the command without getting the error.
The problem was as James Henstridge commented, for some reason there was an issue with my user directory name case. Even though the directory is lowercase, I had to make it capitalized.
This worked:
GOPATH=/Users/Daryl/go
This didn't:
GOPATH=$HOME/go
However, since moving to a rMBP from my iMac, I had no problems whatsoever setting up Go, so, to this day, I'm not sure what was going on, but in that instance the capitalization fixed it.
I had the same problem in Windows 10,
So I set a system variable named GOBIN
with absolute value F:\go\bin.
Then ran go install main.go and everything worked perfectly fine!

Why is go install writing binary in the src directory?

I have a small go program in the directory:
~/gocode/src/github.com/elviejo79/goexample/
When I execute
go install
The program does compile but it leaves the executable in the same directory as the code.
but according to How to Write Go Code the binary should in fact be saved at
~/gocode/bin
this my $GOPATH
$ echo $GOPATH
/home/agarcia/gocode
Cannot reproduce this. Please Enter
$ go env
And verify where your GOBIN points to. For example, at the machine I'm right now, it says
09:01 myname#tux64:~$ go env
GOARCH="amd64"
GOBIN="/home/myname/bin"
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myname"
GOROOT="/home/myname/go"
GOTOOLDIR="/home/myname/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
09:01 myname#tux64:~$
The go tool should send the binary to $GOBIN. Here it works like that.

Resources