VS Code is able to go get. Why can't I?

xuanbao · · 552 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am on Windows, using VS Code with the official go extension.</p> <p>VS Code is able to <code>go get</code> any missing package for <a href="http://imgur.com/a/PcHb8" rel="nofollow">its commands</a>. When I try to do it though, in cmd.exe or in the VsCode terminal, it tells me &#34;go&#34; is undefined blabla (like if the go binaries weren&#39;t in $PATH or something).</p> <p>Is there a way to install a go package easily from inside VS Code? I am trying to install <a href="http://surf.readthedocs.io/" rel="nofollow">http://surf.readthedocs.io/</a></p> <hr/>**评论:**<br/><br/>daenney: <pre><p>The reason that it works in VS Code is because the vscode-go plugin has <a href="https://github.com/Microsoft/vscode-go/blob/224c330327124c965cc9f9075d9a410181587cb4/src/goPath.ts#L91-L96" rel="nofollow">some heuristics to try and find the <code>go</code> binary. If all else fails on Windows, it falls back to <code>C:\Go</code></a>, which happens to be the default install location. So unless you&#39;ve installed it somewhere else vscode will find it just fine, but since you&#39;ve not added it to your <code>$PATH</code> any CLI based interaction won&#39;t work.</p></pre>reblaw7: <pre><p>Question, does &#34;go version&#34; return the expected results in your terminal? I just ask because windows can be finicky sometimes, and if the issue is windows finding the binary in the path, that should be looked at first. I&#39;ve found sometimes opening a new terminal window helps, other times a full reboot is what takes to get it working. </p></pre>reblaw7: <pre><p>Also, it&#39;s nice to see another Windows Gopher. </p></pre>au_travail: <pre><p>No, go isn&#39;t in the $PATH, so any <code>go xxx</code> doesn&#39;t work. Still VS Code is able to do <code>go get</code> so I&#39;d like to do it too.</p></pre>deusmetallum: <pre><p>If the go binary location isn&#39;t in $PATH then your machine simply has no way of knowing where to get it from. Maybe VSCode has some built in locations that it tries if it is not in $PATH, I don&#39;t know, but you need to add it to yours.</p></pre>1lann: <pre><p>Try adding Go to your path manually? By default it&#39;s installed to C:\Go, is it there? If so you can add C:\Go\bin to your path.</p></pre>au_travail: <pre><p>Thank you, I will. Shame VSCode doesn&#39;t allow automatic installation of missing libraries though.</p></pre>markole: <pre><p>Why would it? It is a code editor, not package manager for Windows.</p></pre>au_travail: <pre><p>It automatically gets a lot of stuff though. Like goreturns and stuff. The go extension could also look for used libraries in code and automatically add them.</p></pre>markole: <pre><p>Well, that isn&#39;t done by VSCode per se but by the Golang extension.</p> <p>Also, I wouldn&#39;t like for an extension to compile random code from the internet because I typed an import path.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

552 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传