【问题标题】:Calling Rust cargo from R results in "cargo not found" error on macOS从 R 调用 Rust cargo 会导致 macOS 上出现“cargo not found”错误
【发布时间】:2021-02-19 03:17:30
【问题描述】:

在 macOS 11.2.1 上从 RStudio 运行 R

从 R 调用 cargo 时,如使用 rextendr 包或尝试安装 helloextendr 时,我分别收到错误 sh: cargo: command not foundmake: cargo: command not found。但是,从终端调用 cargo 可以正常工作。

从下面可以看出区别。

在 R 中未找到货物:

> Sys.which("cargo")
# cargo
# ""

从一个码头发现货物

% which cargo
$HOME/.cargo/bin/cargo

【问题讨论】:

    标签: r rust


    【解决方案1】:

    原因与这个问题有关:Why do which and Sys.which return different paths? 简单地说,macOS 有一个不同的 $PATH 变量,这取决于你是直接使用终端还是使用从 Dock 启动的应用程序(就像 R 和 RStudio 一样)。

    一种解决方案是使用 .Rprofile 文件。将以下行添加到主目录或项目主目录中的 .Rprofile。 (有关 .Rprofile 文件的更多信息,请参阅here。)

    # R can't find Rust's cargo binary
    # issue is because $PATH is different for shell vs. dock launched applications in MacOS
    # See: https://stackoverflow.com/questions/48084679/why-do-which-and-sys-which-return-different-paths
    Sys.setenv(PATH = paste0("/Users/username/.cargo/bin:", Sys.getenv("PATH")))
    
    

    确保“用户名”是您的用户名。比如我的路径是“/Users/tommy/.cargo/bin:”

    这会将default location of Rust installation 附加到 R 在启动时收到的 $PATH 变量中。

    【讨论】:

      猜你喜欢
      • 2022-11-10
      • 1970-01-01
      • 2015-03-28
      • 2020-01-15
      • 2022-09-25
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      相关资源
      最近更新 更多