duanjiao5723 2017-02-23 06:34
浏览 146
已采纳

NameError:名称“ go”未在sublime text 3控制台中定义

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

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

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:

>>> go
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'go' 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: ['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

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

  • 写回答

1条回答 默认 最新

  • dsf6281 2017-02-23 06:48
    关注

    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:

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

    will run the currently opened file when triggered.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)