代码之家  ›  专栏  ›  技术社区  ›  Drew Mikels

我无法在OSX上的VS代码中的终端中运行我的代码

  •  0
  • Drew Mikels  · 技术社区  · 3 年前

    每当我试图以各种方式运行程序时,我都会遇到以下错误,我认为这些方法应该有效:

    drew@Drews-MacBook-Pro Golang % sudo go run .\Golang exercises
    Password: <password entered>
    no required module provides package .Golang: go.mod file not
        found in current directory or any parent directory:
        see 'go help modules'
    
    drew@Drews-MacBook-Pro Golang % cd /users/drew/Documents/Golang/Golang exercises
    cd: string not in pwd: /users/drew/Documents/Golang/Golang
    
    drew@Drews-MacBook-Pro Golang % sudo go .\Golang exercises
    Password: <password entered>
    go: .Golang: unknown command
    Run 'go help' for usage.
    
    drew@Drews-MacBook-Pro Golang % sudo go run .\Golang exercises
    Password: <password entered>
    no required module provides package .Golang: go.mod file not
        found in current directory or any parent directory:
        see 'go help modules'
    

    它似乎没有连接到正确的目录,但我不确定这是否是确切的问题。我跑步时使用 sudo 并更改了目录,但无济于事。

    1 回复  |  直到 3 年前
        1
  •  0
  •   paxdiablo    3 年前

    我在这里看到了一些问题。


    首先,OSX是一个类似UNIX的系统,其中路径分隔符是“正常”斜杠, / .

    反斜杠被用作转义符,用于诸如 \t (选项卡)和 \n (换行符)。

    自从 . 不是此上下文中的特殊转义符之一,序列 \. 只是被当作 \ 不在那里(所以 . ,这就是它抱怨的原因 .Golang ).


    其次,如果文件名或路径名中有空格,则必须引用它们,以便shell将它们视为单个参数。

    如果没有这一点,像这样的命令

    mkdir /Users/drew/Documents/Golang/Golang exercises
    

    将尝试使 二 目录 /Users/drew/Documents/Golang/Golang 和 ./exercises ,而不是 仅有一个的 包含空间的目录。


    你的问题中的一些命令的例子 二者都 这些考虑点将是:

    sudo go run './Golang exercises'                   # Slash, quote.
    cd '/Users/drew/Documents/Golang/Golang exercises' # Quote.