package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%. How to get remote golang packages?

huangapple go评论94阅读模式
英文:

package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%. How to get remote golang packages?

问题

我按照Golang教程http://golang.org/doc/code.html#remote中的说明进行操作。

我的环境设置如下:

C:\sbox\go\example>set go
    GOPATH=C:\sbox\go\example
    GOROOT=C:\Go

example/文件夹下只有一个src/文件夹:

C:\sbox\go\example\
             |
             --src\

然后我按照说明调用go get命令,但是出现了错误:

C:\sbox\go\example>go get code.google.com/p/go.example/hello
# cd .; hg clone -U https://code.google.com/p/go.example C:\sbox\go\example\src\code.google.com\p\go.example
package code.google.com/p/go.example/hello: exec: "hg": 在 %PATH% 中找不到可执行文件

调用go get之后,我的example/文件夹变成了这样:

C:\sbox\go\example\
             |
             --src\
                |
                code.google.com\
                       |
                       --p\

然后我在我的目录结构中添加了一些代码,变成了这样:

C:\sbox\go\example\
             |
             --src\
                |
                ---code.google.com\
                |        |
                |        --p\
                |
                ---github.com\
                       |
                       --user\
                           |
                           --hello\
                           |   |
                           |   --hello.go
                           |
                           --newmath\
                                |
                                --sqrt.go

hello.go的内容如下:

package main

import (
	"fmt"
	"github.com/user/newmath"
	//"code.google.com/p/go.example/newmath"
)

func main() {
	fmt.Printf("Hello, world.  Sqrt(2) = %v\n", newmath.Sqrt(2))
}

sqrt.go的内容如下:

// Package newmath is a trivial example package.
package newmath

// Sqrt returns an approximation to the square root of x.
func Sqrt(x float64) float64 {
	z := 0.0
	for i := 0; i < 1000; i++ {
		z -= (z*z - x) / (2 * x)
	}
	return z
}

我只是复制/粘贴了它们。都按照教程中的说明进行操作。然后我运行go install并运行项目。一切正常:

C:\sbox\go\example\src\github.com\user\hello>go install
    
C:\sbox\go\example\bin>hello
Hello, world.  Sqrt(2) = 1.414213562373095

然后我再次运行go get,但是出现了相同的错误:

C:\sbox\go\example>go get code.google.com/p/go.example/hello
# cd .; hg clone -U https://code.google.com/p/go.example C:\sbox\go\example\src\code.google.com\p\go.example
package code.google.com/p/go.example/hello: exec: "hg": 在 %PATH% 中找不到可执行文件

好的,我将bin/目录添加到PATH中并再次运行go get,但是仍然出现相同的错误:

C:\sbox\go\example>set PATH=%PATH%;C:\sbox\go\example\bin

C:\sbox\go\example>go get code.google.com/p/go.example/hello
# cd .; hg clone -U https://code.google.com/p/go.example C:\sbox\go\example\src\code.google.com\p\go.example
package code.google.com/p/go.example/hello: exec: "hg": 在 %PATH% 中找不到可执行文件

我需要做什么才能按照教程中的说明获得结果 - 安装远程包并使用它们?

英文:

I do as written an the Golang tutorial http://golang.org/doc/code.html#remote

My env settings:

C:\sbox\go\example>set go
    GOPATH=C:\sbox\go\example
    GOROOT=C:\Go

The example/ folder has only src/ folder:

C:\sbox\go\example\
             |
             --src\

Now I call go get as described and get an error:

C:\sbox\go\example>go get code.google.com/p/go.example/hello
# cd .; hg clone -U https://code.google.com/p/go.example C:\sbox\go\example\src\code.google.com\p\go.example
package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%

After calling go get, though, my example/ folder becomes like this:

C:\sbox\go\example\
             |
             --src\
                |
                code.google.com\
                       |
                       --p\

And that's all. Nothing more installed.

Then I add a code to my directory structure and it becomes like this:

C:\sbox\go\example\
             |
             --src\
                |
                ---code.google.com\
                |        |
                |        --p\
                |
                ---github.com\
                       |
                       --user\
                           |
                           --hello\
                           |   |
                           |   --hello.go
                           |
                           --newmath\
                                |
                                --sqrt.go

hello.go is like this:

package main

import (
	"fmt"
	"github.com/user/newmath"
	//"code.google.com/p/go.example/newmath"
)

func main() {
	fmt.Printf("Hello, world.  Sqrt(2) = %v\n", newmath.Sqrt(2))
}

sqrt.go is like this:

// Package newmath is a trivial example package.
package newmath

// Sqrt returns an approximation to the square root of x.
func Sqrt(x float64) float64 {
	z := 0.0
	for i := 0; i < 1000; i++ {
		z -= (z*z - x) / (2 * x)
	}
	return z
}

I just cope/paste them. All as written in the tutorial. Then I do go install and run the project. All works fine:

C:\sbox\go\example\src\github.com\user\hello>go install
    
C:\sbox\go\example\bin>hello
Hello, world.  Sqrt(2) = 1.414213562373095

Now I again run go get and get the same error:

C:\sbox\go\example>go get code.google.com/p/go.example/hello
# cd .; hg clone -U https://code.google.com/p/go.example C:\sbox\go\example\src\code.google.com\p\go.example
package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%

Ok, I add bin/ directory to the PATH and run go get again but get the same error:

C:\sbox\go\example>set PATH=%PATH%;C:\sbox\go\example\bin

C:\sbox\go\example>go get code.google.com/p/go.example/hello
# cd .; hg clone -U https://code.google.com/p/go.example C:\sbox\go\example\src\code.google.com\p\go.example
package code.google.com/p/go.example/hello: exec: "hg": executable file not found in %PATH%

What do I need to do get the result as described in the tutorial - remote packages are installed and I can use them?

答案1

得分: 18

你正在尝试安装的软件包是使用Mercurial(hg)源代码控制系统的。你需要安装Mercurial才能克隆该软件包。

英文:

The package you are trying to install is under the Mercurial (hg) source control system. You need to install Mercurial to be able to clone the package.

huangapple
  • 本文由 发表于 2013年6月3日 23:34:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/16900486.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定