can't load package: package .: no buildable Go source files

Go

Go Problem Overview


Here is the error message:

% go get     
can't load package: package .: no buildable Go source files in /Users/7yan00

% echo $GOPATH     
/Users/7yan00/Golang

How would you troubleshoot that error?

Go Solutions


Solution 1 - Go

Make sure you are using that command in the Go project source folder (like /Users/7yan00/Golang/src/myProject).

One alternative (similar to this bug) is to use the -d option (see go get command)

go get -d

> The -d flag instructs get to stop after downloading the packages; that is, it instructs get not to install the packages.

See if that helps in your case.


But more generally, as described in this thread:

> go get is for package(s), not for repositories. > > so if you want a specific package, say, go.text/encoding, then use

go get code.google.com/p/go.text/encoding

> if you want all packages in that repository, use ... to signify that:

go get code.google.com/p/go.text/...

Solution 2 - Go

You should check the $GOPATH directory. If there is an empty directory of the package name, go get doesn't download the package from the repository.

For example, If I want to get the github.com/googollee/go-socket.io package from it's github repository, and there is already an empty directory github.com/googollee/go-socket.io in the $GOPATH, go get doesn't download the package and then complains that there is no buildable Go source file in the directory. Delete any empty directory first of all.

Solution 3 - Go

Another possible reason for the message: > can't load package: .... : no buildable Go source files

Is when the source files being compiled have:

// +build ignore

In which case the files are ignored and not buildable as requested.This behaviour is documented at https://golang.org/pkg/go/build/

Solution 4 - Go

To resolve this for my situation:

I had to specify a more specific sub-package to install.

Wrong:

go get github.com/garyburd/redigo

Correct:

go get github.com/garyburd/redigo/redis

Solution 5 - Go

If you want all packages in that repository, use ... to signify that, like:

go get code.google.com/p/go.text/...

Solution 6 - Go

you can try to download packages from mod

go get -v all

Solution 7 - Go

I had this exact error code and after checking my repository discovered that there were no go files but actually just more directories. So it was more of a red herring than an error for me.

I would recommend doing

> go env

and making sure that everything is as it should be, check your environment variables in your OS and check to make sure your shell (bash or w/e ) isn't compromising it via something like a .bash_profile or .bashrc file. good luck.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question7yan00View Question on Stackoverflow
Solution 1 - GoVonCView Answer on Stackoverflow
Solution 2 - GoBurtKView Answer on Stackoverflow
Solution 3 - GoJoao CostaView Answer on Stackoverflow
Solution 4 - GoDonn LeeView Answer on Stackoverflow
Solution 5 - Gouser3072851View Answer on Stackoverflow
Solution 6 - GoSTEELView Answer on Stackoverflow
Solution 7 - GoDavid HunsickerView Answer on Stackoverflow