Golang go get第三方库的坑

ENV

  • Ubuntu 18.04
  • Golang 1.10.2

 

在树莓派上go get fail的问题记录及解决方案

go get github.com/terrancewong/serial

 

# 错误为GOPATH路径的问题

cannot find package "github.com/terrancewong/serial" in any of:...

/usr/lib/go-1.7/src/github.com/terrancewong/serial (from $GOROOT)
/home/pi/go/src/github.com/terrancewong/serial (from $GOPATH)

Solve:.bashrc加入gopath 后go get success

cd ~
// 在home/ 统一建立一个存放src和pkg的文件夹go
mkdir go 
vim .bashrc
// add GOPATH in file tail
export GOPATH=~/go
// exit and source 
source .bashrc

 

# unix包含低级操作系统原语的接口  -- 导入失败

package golang.org/x/sys/unix: unrecognized import path "golang.org/x/sys/unix" (https fetch: Get https://golang.org/x/sys/unix?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

Solve:导入相关库

// 进入gopath的src目录:
cd ~/go/src 
// 创建目录: 
mkdir -p golang.org/x/ 
//进入刚创建的目录: 
cd golang.org/x 
// 克隆git库:
git clone https://github.com/golang/sys.git
posted @ 2019-01-24 19:48  kumata  阅读(982)  评论(0编辑  收藏  举报