NameError: 在Sublime Text 3控制台中,名称’go’未定义。

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

NameError: name 'go' is not defined in sublime text 3 console

问题

我按照某个网页的指示安装了Sublime Text 3,并使用包管理工具安装了Gosublime,然后修改了它的用户默认文件:

{
   "env": {
       "GOROOT": "d:\\go",
       "GOPATH": "d:\\go\\workspace",
       "path": "d:\\go\\workspace\\bin"
   }
}

其中d:\go是我之前下载和安装的golang环境,d:\go是我创建的工作空间。现在我想安装gocode。我重新启动了Sublime Text 3,然后打开控制台。当我输入以下命令时:

git get github.com/nsf/gocode

它显示:

>>> go
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'go' is not defined

下面是完整的控制台日志供参考:

GoSublime init r17.02.16-1 (0.001s)
|   install margo: no
|   install state: done
| sublime.version: 3126
| sublime.channel: stable
|       about.ann: a17.02.16-1
|   about.version: r17.02.16-1
|         version: r17.02.16-1
|        platform: windows-x64
|            ~bin: ~\AppData\Roaming\Sublime Text 3\Packages\User\GoSublime\windows-x64\bin
|       margo.exe: ~bin\gosublime.margo_r17.02.16-1_go1.8.exe (ok)
|          go.exe: d:\go\bin\go.exe (ok)
|      go.version: go1.8
|          GOROOT: d:\go
|          GOPATH: d:\go\workspace
|           GOBIN: (not set) (should usually be `(not set)`)
|       set.shell: []
|       env.shell:
|       shell.cmd: ['C:\\windows\\system32\\cmd.exe', '/C', '${CMD}']
--------------------------------

Package Control: Skipping automatic upgrade, last run at 2017-02-23 14:07:30, next run at 2017-02-23 15:07:30 or after
>>> go
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'go' is not defined
>>> go get github.com/nsf/gocode
  File "<string>", line 1
    go get github.com/nsf/gocode
         ^
SyntaxError: invalid syntax

但是,如果我运行cmd.com并输入相同的命令,它可以正常运行。我错过了什么?

英文:

I follow some webpage's instructions to install Sublime Text 3 and use package control to install Gosublime, then change its user-default file:

{
   &quot;env&quot;: {
       &quot;GOROOT&quot;: &quot;d:\\go&quot;,
       &quot;GOPATH&quot;: &quot;d:\\go\workspace&quot;,
       &quot;path: &quot;d:\\go\\workspace\\bin&quot;
   }
}

where d:\go is the golang environement I downloaded and installed earlier, d:\go is the workspace I established. Now I want to install gocode. I restart Sublime Text 3, then show console. Wen I enter

git get github.com/nsf/gocode

It shows:

&gt;&gt;&gt; go
Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
NameError: name &#39;go&#39; is not defined

Below is the complete console log for reference:

GoSublime init r17.02.16-1 (0.001s)
|   install margo: no
|   install state: done
| sublime.version: 3126
| sublime.channel: stable
|       about.ann: a17.02.16-1
|   about.version: r17.02.16-1
|         version: r17.02.16-1
|        platform: windows-x64
|            ~bin: ~\AppData\Roaming\Sublime Text 3\Packages\User\GoSublime\windows-x64\bin
|       margo.exe: ~bin\gosublime.margo_r17.02.16-1_go1.8.exe (ok)
|          go.exe: d:\go\bin\go.exe (ok)
|      go.version: go1.8
|          GOROOT: d:\go
|          GOPATH: d:\go\workspace
|           GOBIN: (not set) (should usually be `(not set)`)
|       set.shell: []
|       env.shell:
|       shell.cmd: [&#39;C:\\windows\\system32\\cmd.exe&#39;, &#39;/C&#39;, &#39;${CMD}&#39;]
--------------------------------

Package Control: Skipping automatic upgrade, last run at 2017-02-23 14:07:30, next run at 2017-02-23 15:07:30 or after
&gt;&gt;&gt; go
Traceback (most recent call last):
  File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
NameError: name &#39;go&#39; is not defined
&gt;&gt;&gt; go get github.com/nsf/gocode
  File &quot;&lt;string&gt;&quot;, line 1
    go get github.com/nsf/gocode
         ^
SyntaxError: invalid syntax

But if I run cmd.com and enter same command, it runs ok. What do I miss?

答案1

得分: 3

Sublime Text控制台不是一个终端,它是一个Python shell。你可以运行Python命令,而不是Bash(Windows)命令。

正如@keith Hall在他的命令中所说,要运行Bash命令,你需要一些构建系统。不过,我不认为这是你的问题的解决方案,因为你只想运行这个命令一次,对吗?如果是这样的话,你可能想看看sublimeREPL,不过我建议你直接使用一个普通的终端。

简单来说:

构建系统非常有用,可以用来运行例如Python程序。一个非常简单的构建系统如下所示:

{
    "cmd": ["python", "$file"]
}

将在触发时运行当前打开的文件。

关于构建系统的更多信息,可能没有比非官方文档更好的资源了。

英文:

The Sublime Text console is not a terminal, it's a python shell. You can run python command, not bash (windows) commands.

As said @keith Hall in his command, to run bash commands, you need some build systems. I don't believe that's the solution to your problem, though, since you only want to run this command once, no? If it's the case, you might want to look at sublimeREPL, although I'd recommend simply using a regular terminal.

Just a quick overview:

Build systems are super useful to run for example python program. A really simple build system like this:

{
    &quot;cmd&quot;: [&quot;python&quot;, &quot;$file&quot;]
}

will run the currently opened file when triggered.

For more about build system, there's probably no better resource than the unofficial documentation

答案2

得分: -1

你需要添加这行代码 import plotly.graph_objects as go
#Python

英文:

You have to add this line import plotly.graph_objects as go.
#Python

huangapple
  • 本文由 发表于 2017年2月23日 14:34:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/42408642.html
匿名

发表评论

匿名网友

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

确定