“unrecognized import path” with go get

后端 未结 9 769
你的背包
你的背包 2020-12-07 18:00

I\'m trying to install a web.go, but running go get github.com/hoisie/web returns

package bufio: unrecognized import path \"bufio\"         


        
相关标签:
9条回答
  • 2020-12-07 18:37

    $ unset GOROOT worked for me. As most answers suggest your GOROOT is invalid.

    0 讨论(0)
  • 2020-12-07 18:38

    I had exactly the same issue, after moving from old go version (installed from old PPA) to newer (1.2.1) default packages in ubuntu 14.04.

    The first step was to purge existing go:

    sudo apt-get purge golang*
    

    Which outputs following warnings:

    dpkg: warning: while removing golang-go, directory '/usr/lib/go/src' not empty so not removed
    dpkg: warning: while removing golang-go.tools, directory '/usr/lib/go' not empty so not removed
    

    It looks like removing go leaves some files behind, which in turn can confuse newer install. More precisely, installation itself will complete fine, but afterwards any go command, like "go get something" gives those "unrecognized import path" errors.

    All I had to do was to remove those dirs first, reinstall golang, and all works like a charm (assuming you also set GOPATH)

    # careful!
    sudo rm -rf /usr/lib/go /usr/lib/go/src
    sudo apt-get install golang-go golang-go.tools
    
    0 讨论(0)
  • 2020-12-07 18:39

    I encountered this issue when installing a different package, and it could be caused by the GOROOT and GOPATH configuration on your PATH. I tend not to set GOROOT because my OS X installation handled it (I believe) for me.

    1. Ensure the following in your .profile (or wherever you store profile configuration: .bash_profile, .zshrc, .bashrc, etc):

      export GOPATH=$HOME/go
      export PATH=$PATH:$GOROOT/bin
      
    2. Also, you likely want to unset GOROOT, as well, in case that path is also incorrect.

    3. Furthermore, be sure to clean your PATH, similarly to what I've done below, just before the GOPATH assignment, i.e.:

      export PATH=$HOME/bin:/usr/local/bin:$PATH
      export GOPATH=$HOME/go
      export PATH=$PATH:$GOROOT/bin
      
    4. Then, source <.profile> to activate

    5. retry go get
    0 讨论(0)
  • 2020-12-07 18:40

    I installed Go with brew on OSX 10.11, and found I had to set GOROOT to:

    /usr/local/Cellar/go/1.5.1/libexec

    (Of course replace the version in this path with go version you have)

    Brew uses symlinks, which were fooling the gotool. So follow the links home.

    0 讨论(0)
  • 2020-12-07 18:45

    I had the same issue after having upgraded go1.2 to go1.4.

    I renamed src to _src in my GOPATH then did a go get -v

    It worked then I deleted _src.

    Hope it helps.

    0 讨论(0)
  • 2020-12-07 18:48

    The issues are relating to an invalid GOROOT.

    I think you installed Go in /usr/local/go.
    So change your GOROOT path to the value of /usr/local/go/bin.

    It seems that you meant to have your workspace (GOPATH) located at /home/me/go.

    This might fix your problem.
    Add this to the bottom of your bash profile, located here => $HOME/.profile

    export GOROOT=/usr/local/go
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOROOT/bin
    

    Make sure to remove the old references of GOROOT.

    Then try installing web.go again.

    If that doesn't work, then have Ubuntu install Go for you.

    sudo apt-get install golang

    Video tutorial: http://www.youtube.com/watch?v=2PATwIfO5ag

    0 讨论(0)
提交回复
热议问题