Importing from GitHub not working

I am working with the Measure The Future software and they import from their GitHub account, the code does not seem to work, giving error cannot find package from a directory/file that cannot be resolved. How can I make imports from websites work, this is their open source code, not changed.

The answer to this here:

> post 7296

do you need set the GOPATH and configure your IDE how link below

I tried this and I don’t really see how it helps with importing code from outside of the directory. I can import fine from within.

It is not about import, it is about the IDE to identify a library and its dependencies,

if you only want to import just run:
go get your package

Ok so what would the syntax of that look like? I am very confused because I don’t get why it would work for them but have to be changed for other use. I also didn’t have those options in the comment picture you posted.

Did you follow the steps from the project’s readme, especially step 10?

I am asking because the error you described indicates that the packages have not been downloaded to your computer. Be aware that the import directive knows nothing about Web sites, all import paths are just local paths, even though they may look like URL’s.

The only Go tool that is aware of repositories on remote Web sites is go get. For example, the command

go get github.com/MeasureTheFuture/scout

downloads the scout package and all packages that it depends on from GitHub to your computer, into a directory with the same path as the URL (that is, $GOPATH/src/github.com/MeasureTheFuture/scout).

1 Like

That is the reason I am asking Christopher, I cloned all of the repositories and it works if I say “./configuration” but not if the entire url is present. I would be happy to allow this to occur but I need to access other repositories, namely the mothership and 2 other repositories which MeasureTheFuture also borrow from. I don’t quite understand what I have done wrong. I am very new to Golang, I am basically learning so I can do this project. I tried the go get method but there were problems that occurred from it.

the import statements looks for packages present in your local machine.

For example, import github.com/MeasrueTheFuture/scout/configuration will look for the package in $GOPATH/src/github.com/MeasrueTheFuture/scout/configuration.
You can check the exact location in your local whether the packages are present or not. If not go get github.com/MeasrueTheFuture/scout should end up doing that.
If go get does not work, you can manually download the github repo and place it under the location mentioned above.

This seems to point to a GOPATH issue then, as @luk4z7 already suggested.

As you are using an IDE, I recommend two steps.

First, open a shell and type

go env GOPATH

to reveal the root of your Go workspace. Then starting from this root directory, verify if the scout packages reside under src/github.com/MeasureTheFuture/scout.
If this is the case, retry the go build step from the readme (that is, outside the IDE). If this works but the IDE fails, you’ll need to check your IDE settings.

Step 2: If the GOPATH root directory and the location of the scout package do not match, then go get appears to have used a different GOPATH than you have now.

I suspect that the installation step 10 from the readme can cause this. On closer inspection, I noticed that step 10 sets the GOPATH locally before go getting and go building things:

$ cd ..
$ export GOPATH=`pwd` # This only affects the local shell and any subshell.
$ go get github.com/MeasureTheFuture/scout
$ go get github.com/onsi/ginkgo
$ go get github.com/onsi/gomega
$ go get -u github.com/mattes/migrate

Instead of export GOPATH=pwd I would recommend cd’ing into the existing GOPATH:

cd $(go env GOPATH)
go get... etc

(The syntax of the $(...) part may differ depending on the shell you use.)

Usually, there is only a single GOPATH (that defaults to $HOME/go on Unix, or %USERPROFILE%\go on Windows if no GOPATH environment variable is set), but some IDE’s attempt to juggle multiple GOPATHs, which can get messy. Also setting a local ad-hoc GOPATH like the scout install steps do just seems to beg for problems.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.