doudou201701 2018-06-29 22:31
浏览 227
已采纳

在以下任何位置都找不到软件包“ github.com/gorrila/mux”

The error message is:

app.go:9:3: cannot find package "github.com/gorrila/mux" in any of:
    /usr/local/Cellar/go/1.10.3/libexec/src/github.com/gorrila/mux (from 
$GOROOT)
    /Users/myname/go/src/github.com/gorrila/mux (from $GOPATH)

I understand GOROOT is for compiler tools that come with installation, so I am not sure why it looks for mux there. But I do see mux in the second location in my directory I created for go code.

I know this question was asked once before and I tried to debug following the advice from that question.

I used homebrew and installed go version go1.10.3 darwin/amd64.

Here is what I believe to be the relevant portion of my go env:

GOPATH="/Users/myname/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"

I also set my bash profile, excluding GOROOT because that is no longer required:

export GOPATH="/Users/myname/go/src/github.com"
export PATH="/Users/myname/go/src/github.com/bin:$PATH"

And did source ~/.bash_profile.

This setup was enough that I can run basic go programs like hello world. So I then tried to run code using the mux library.

I first installed mux within the directory of my program (cd'd into /Users/myname/go/src/github.com/myname/restapi).

Then I ran:

go get -u github.com/gorilla/mux

I can see the folder exists in my finder. I also looked in terminal:

ls -l /Users/myname/go/src/github.com | grep gorilla
=> drwxr-xr-x  3 myname  staff  102 Jun 29 14:35 gorilla

Then:

cd $GOPATH (/Users/myname/go)
go list ... | grep gorilla 
=> can't load package: package ../..: no Go files in /Users

So I saw gorilla in the first command but not the second. However, I do see the gorilla directory further within my go directory, so I'm not sure what the issue is.

Running go build returns the package of concern:

app.go:9:3: cannot find package "github.com/gorrila/mux" in any of:
      /usr/local/Cellar/go/1.10.3/libexec/src/github.com/gorrila/mux 
(from $GOROOT)
  /Users/myname/go/src/github.com/gorrila/mux (from $GOPATH)

I am not sure why it is looking for mux within the usr directory. Is there an issue with any of my paths? I keep checking that last path to see that the mux directory is there.

  • 写回答

2条回答 默认 最新

  • dongpu2727 2018-06-30 16:33
    关注

    It looks like you misspelled "github.com/gorilla/mux" – it has one "r" and two "l"'s. (Carefully compare the go get command you quoted and the import statement in your source file.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵