45

golang 遇到go get下载golang.org/x/net/context失败问题(windows解决方案)

 5 years ago
source link: https://studygolang.com/articles/19884?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

错误信息: package golang.org/x/net/context: unrecognized import path "golang.org/x/net/context"

类似错误信息:

package golang.org/x/net/context: unrecognized import path "golang.org/x/net/context" (https fetch: Get https://golang.org/x/net/context?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

windows解决方案:

1.打开PowerShell(本人是win10系统,和CMD打开程序一样,输入PowerShell搜索PowerShell,然后打开)

2.在PowerShell中输入如下两个命令

$env:GOPROXY = "https://goproxy.io"

$env:GO111MODULE="on"

3.开始在PowerShell中go get项目,执行下面命令:

go get github.com/项目

4.此时我遇到问题:

exec: "gcc": executable file not found in %PATH%

解决exec: "gcc": executable file not found in %PATH%问题:

1.下载MinGW

MinGW分为较早开发的MinGW32和之后为编译64位程序开发的MinGW-w64,MinGW32只能编译32位的程序,而mingw64不仅能编译64位程序,也能编译32位程序,还能进行交叉编译,即在32位主机上编译64位程序,在64位主机上编译32位程序。

由于用的window10 企业版64位操作系统,要下载mingw 64位(官网地址: http://mingw-w64.org/doku.php ),下载地址: https://sourceforge.net/projects/mingw-w64/

2.点击exe文件,一步步安装MinGW

3.配置MinGW环境变量,在环境变量PATH中新增:C:\mingw-w64\i686-6.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin

4. 在cmd下,打开C:\mingw-w64\i686-6.2.0-posix-dwarf-rt_v5-rev1\mingw32\bin目录,输入gcc -v,出现如下图,说明安装成功:

BJ7Vfyv.png!web

5.然后重新在PowerShell中执行:go get github.com/taigacute/DailyTasks(如还有同样问题,请重启PowerShell,然后重新设置$env:GOPROXY, $env:GO111MODULE)

6.此时会再GOPATH下src目录发现下载的项目。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK