When trying to run godep save, I'm always getting the following error:
godep: [WARNING]: godep should only be used inside a valid go package directory and
godep: [WARNING]: may not function correctly. You are probably outside of your $GOPATH.
godep: [WARNING]: Current Directory: /Users/username/Development/my-server
godep: [WARNING]: $GOPATH: /Users/username/Development/my-server
Does anyone know how to solve this issue?
You want to make sure that you run this command from a repo that is also defined in your $GOPATH.
So it would need to be: /Users/username/gosource/src/github/foo/my-server/
This means that not only are all your packages located in your $GOPATH but additionally your own repo is located in your $GOPATH. At this point everything should work as expected.
If you don't have a $GOPATH environment variable defined you need to make sure it is set pre Go1.8.
Try this: echo $GOPATH at the command prompt to see if it's defined.
If not, you'll want to choose a location and set it with: export GOPATH=/your/final/location.
More details can be found here.
Related
I was trying to build influx/telegraf locally and vendor all the packages using go mod vendor command. However, interestingly, the build fails after that with the following error:
# github.com/shirou/gopsutil/host
vendor/github.com/shirou/gopsutil/host/host_darwin_cgo.go:9:11: fatal error: 'include/smc.c' file not found
#include "include/smc.c"
^~~~~~~~~~~~~~~
Steps to reproduce (after setting GOPATH variable):
# Fetch the project, e.g. influx/telegraf
go get -d github.com/influxdata/telegraf
# CD into the project
cd $GOPATH/src/influxdata/telegraf
# Checkout v1.14.5 (the current latest version)
git checkout v1.14.5
# Fetch the modules under vendor/ directory
go mod vendor
# Then modify the Makefile as follows:
# 1. Remove the `deps` target and its reference in the `all` target; it is not needed anymore, as we fetched all modules.
# 2. Add the `-mod vendor` flag everywhere `go build`, `go install`, or `go test` is called. This is necessary since Telegraf v1.14.5 is still on version 1.12 of Go, which requires this flag to use the modules under `vendor/` directory.
# Finally, build the project and you should get the error above
make
It turned out that this error is caused by a well known issue whereby go mod vendor prunes non-package directories, hence causing the host/include folder of shirou/gopsutil, which contains the smc.c file, to be pruned:
https://github.com/golang/go/issues/26366
The impact of this issue on shirou/gopsutil is already reported:
https://github.com/shirou/gopsutil/issues/832
There is no easy solution apparently, but a work-around for now is to manually copy the missing directories to vendor/github.com/shirou/gopsutil. In my case, I copied freebsd_headers and include from $GOPATH/pkg/mod/github.com/shirou/gopsutil/host to $GOPATH/src/github.com/influxdata/telegraf/vendor/github.com/shirou/gopsutil and it worked.
I hope you find this helpful.
As suggested by #Rafid, you can do a manual copy.
I found this below work-around to be helpful as well.
Run these commands
go get github.com/shirou/gopsutil
go mod vendor
I'm following the gRPC Quickstart tutorial for Go, https://grpc.io/docs/quickstart/go/, and have installed gRPC using the command
go get -u google.golang.org/grpc
I actually haven't defined a GOPATH environment variable:
> echo $GOPATH
which, as I understand it, means that it defaults to ~/go, or in my case /Users/kurt/go.
At the next step, I'd like to build the example by doing
cd $GOPATH/src/google.golang.org/grpc/examples/helloworld
However, I find that the directory doesn't exist, and there is also no google.golang.org directory in /Users/kurt/go/src:
~/g/src> ls *google*
fish: No matches for wildcard '*google*'. See `help expand`.
ls *google*
^
Should the package not be located here? That's what I understand from Where does go get install packages?.
Using Go Modules, you can find 'go get' downloaded files at:
~/go/pkg/mod/cache/download
However, it should be treated like an immutable copy of the source code.
If you want a mutable copy of the source code, you should clone the repository:
git clone https://github.com/grpc/grpc-go
In your example output, you are in ~/g/arc
Go path default would be ~/go/src
I think auto complete bit ya there
In the end, I worked around the problem by cloning https://github.com/grpc/grpc-go which appears to contain the examples/helloworld directory I'm looking for. Still curious to hear where the package downloaded with go get is located.
When I run godep save ./... from the root directory of the project I'm getting the following error. Any clues what might I have to fix?
godep: Unable to find SrcRoot for package .
Filesystem location matters a lot in Go. You’re expected to be running things from a designated ‘gopath’, but don’t confuse gopath with the location of go (don’t just set it to where go is installed).
Your gopath should be a location that you’re happy to put your go source code for the foreseeable future. I’ve set mine to /Users/ejiro/go.
cat <<END >> ~/.bashrc
export GOPATH=/Users/ejiro/go
END
I am new to Go, and I have been working on a Go project locally. I have installed Godep in my local system by:
go get github.com/tools/godep
and then installed Aerospike dependency
go get -u github.com/aerospike/aerospike-client-go
However $GOPATH/bin/godep save ./... gives me following error:-
godep: [WARNING]: godep should only be used inside a valid go package directory and
godep: [WARNING]: may not function correctly. You are probably outside of your $GOPATH.
godep: [WARNING]: Current Directory: /Users/XYZ/go_code/labs-audience
godep: [WARNING]: $GOPATH: /Users/XYZ/go_code
godep: WARNING: Godep workspaces (./Godeps/_workspace) are deprecated and support for them will be removed when go1.8 is released.
godep: WARNING: Go version (go1.6) & $GO15VENDOREXPERIMENT= wants to enable the vendor experiment, but disabling because a Godep workspace (Godeps/_workspace) exists
godep: WARNING: Recorded major go version (go1.5) and in-use major go version (go1.6) differ.
godep: To record current major go version run `godep update -goversion`.
It truncates my Godeps/Godeps.json and Godeps/_workspace/ directory. Please not that I am not panning to upgrade project Go version to 1.6. What wrong am I doing?
Note:
$PROJECT_PATH: $GOPATH/project/
All the commands are being run in $PROJECT_PATH
I am missing the src directory. $GOPATH directory has a certain structure and your projects folder should be located in the src directory.
Can't confirm that this is causing your issue, but it is worth a try: Move your folder labs-audience to /Users/XYZ/go_code/src/labs-audience.
For more information on setting your project up check the Code Organization part on How to Write Go Code.
Note: to keep package paths distinct it is suggested to use a public path for your project. Normally a github (or other vcs path) is used. For example: /Users/XYZ/go_code/src/github.com/YourAccount/labs-audience
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?
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/...
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.
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/
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
If you want all packages in that repository, use ... to signify that, like:
go get code.google.com/p/go.text/...
you can try to download packages from mod
go get -v all
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.