dongou2019 2019-07-27 02:56
浏览 242
已采纳

如何通过内部软件包使用统计功能(MannWhitneyUTest)

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.

  • 写回答

1条回答 默认 最新

  • doubao6464 2019-07-27 03:55
    关注

    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.


    EDIT #1:

    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.

    enter image description here


    EDIT 2:

    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.

    enter image description here

    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"
    

    enter image description here

    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)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含