加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Golang:安装目录错误?

发布时间:2020-12-16 19:18:06 所属栏目:大数据 来源:网络整理
导读:我有错误: go install: no install location for directory /Users/xwilly/Dropbox/go/project/src outside GOPATH 我在OS X上使用了1.1版本。 我可以建立运行但不能安装软件包。 我的环境: GOPATH=/Users/xwilly/Dropbox/go/projectPATH=/Library/Framewo
我有错误:
go install: no install location for directory /Users/xwilly/Dropbox/go/project/src outside GOPATH

我在OS X上使用了1.1版本。

我可以建立&运行但不能安装软件包。

我的环境:

GOPATH=/Users/xwilly/Dropbox/go/project
PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin:/Users/xwilly/Dropbox/go/project/bin

项目树:

/Users/xwilly/Dropbox/go/project
bin
pkg
src

我可以建立没有错误:

..:src xwilly$ go build test.go 
..:src xwilly$ go install test.go
go install: no install location for directory /Users/xwilly/Dropbox/go/project/src outside GOPATH

这是一个简单的例子:

xwilly$ cat test.go 
package main

import (
    "fmt"
)

func main() {
    fmt.Println("Bonjour")
}
xwilly$ go run test.go 
Bonjour
xwilly$ go install test.go 
go install: no install location for directory /Users/xwilly/Dropbox/go/project/src/learning outside GOPATH

07000

07001

Each directory listed in GOPATH must have a prescribed structure:

The src/ directory holds source code. The path below ‘src‘ determines
the import path or executable name.

The pkg/ directory holds installed package objects. As in the Go tree,
each target operating system and architecture pair has its own
subdirectory of pkg (pkg/GOOS_GOARCH).

If DIR is a directory listed in the GOPATH,a package with source in
DIR/src/foo/bar can be imported as “foo/bar” and has its compiled form
installed to “DIR/pkg/GOOS_GOARCH/foo/bar.a“.

The bin/ directory holds compiled commands. Each command is named for
its source directory,but only the final element,not the entire path.
That is,the command with source in DIR/src/foo/quux is installed into
DIR/bin/quux,not DIR/bin/foo/quux. The foo/ is stripped so that you
can add DIR/bin to your PATH to get at the installed commands. If the
GOBIN environment variable is set,commands are installed to the
directory it names instead of DIR/bin.

Here’s an example directory layout:

06000

你的目录结构是错误的。您正在尝试安装一个命令(package main)。它应该在命令中命名的源目录中。请参见上面的quux命令。

在你的情况下,假设你的命令将被命名为比利。

$ mkdir -p /Users/xwilly/Dropbox/go/project/src/billy

在你的GOPATH里面。将您的test.go文件移动到此目录。跑

$ go install billy

命令比利应该,除非你设置GOBIN,安装在

/Users/xwilly/Dropbox/go/project/bin

您的GOPATH中的目录,它应该在您的PATH中。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读