I am trying to run Mann-Whiteney-U test with following code:
package main
import (
"fmt"
"stats"
)
func main() {
e, _ = MannWhitneyUTest([]float64{1, 2, 3, 4, 5},
[]float64{1, 2, 3, 5, 6},
0)
fmt.Println("Mann-WhitneyUTest: ", e)
}
However, this gives me this error:
$ go run mainstats2.go
mainstats2.go:5:2: cannot find package "stats" in any of:
/usr/local/go/src/stats (from $GOROOT)
/home/iuser/go/src/stats (from $GOPATH)
I have following stats packages installed:
$ go list all | grep stats
github.com/montanaflynn/stats
github.com/montanaflynn/stats/examples
golang.org/x/perf/internal/stats
golang.org/x/perf/vendor/github.com/aclements/go-moremath/stats
golang.org/x/perf/vendor/google.golang.org/grpc/stats
I need stats package golang.org/x/perf/ which I had installed by command: go get golang.org/x/perf/internal/stats
I believe this package is already there in go installation and was not needed to be installed separately.
How do I solve this problem? Thanks for your help.
The error occurs because your import path is incorrect, it should be:
import (
"fmt"
"golang.org/x/perf/internal/stats"
)
But even though import path issue is fixed, you'll get another error for trying to use internal package.
stats.go:4:5: use of internal package golang.org/x/perf/internal/stats not allowed
I suggest try to find another alternative library.
If you insist, there is a workaround. Try to copy the $GOPATH/src/golang.org/x/perf/internal/stats
folder directly into your project, then import it. It worked, please see screenshot below.
I have copied the folder to ~/go/src/stats. It is still not working. What should I put for import. Currently it is just "stats"
I think you are doing it wrong. First, you need to create what-so-called project, it's a folder placed inside $GOPATH/src
.
For example in image below I created a project called my-example-app
, placed under $GOPATH/src
. So the full path of the project will be $GOPATH/src/my-example-app
.
Inside my project, I created main.go
file. This file contains the code (I copied from yours).
Also, I copied the $GOPATH/src/golang.org/x/perf/internal/stats
folder into my project, so the stats
folder will be on the same level with my main.go
.
The import of stats
folder need to be happen relative to the project name, so the correct import path would be:
import "my-example-app/stats"
Here is content of my main.go
(copied from yours with some syntax error fix addition).
package main
import (
"fmt"
"my-example-app/stats"
)
func main() {
e, _ := stats.MannWhitneyUTest([]float64{1, 2, 3, 4, 5},
[]float64{1, 2, 3, 5, 6},
0)
fmt.Println("Mann-WhitneyUTest: ", e)
}