【问题标题】:Python subprocess.check_call works in a different way than bashPython subprocess.check_call 的工作方式与 bash 不同
【发布时间】:2019-11-20 13:06:16
【问题描述】:

我正在尝试使用 subprocess.check_call 通过 Python 运行 Rscript。

Rscript 非常简单,它只检查 Rpackage 是否存在,如果不存在,则安装它。

local({r <- getOption("repos")
     r["CRAN"] <- "https://cloud.r-project.org/"
     options(repos=r)
})

if (!require("glue")) install.packages("glue")

当我在 bash 中运行这样的命令时

Rscript packages.R

效果很好。

但是当我尝试使用 subprocess.check_call 运行它时

subprocess.check_call(f"Rscript packages.R",
                      shell=True,
                      env=self.env)

我遇到了这样的错误:

* installing *source* package 'glue' ...
** package 'glue' successfully unpacked and MD5 sums checked
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-3.3.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c glue.c -o glue.o
gcc: error trying to exec 'cc1': execvp: No such file or directory
/usr/lib/R/etc/Makeconf:132: recipe for target 'glue.o' failed
make: *** [glue.o] Error 1
ERROR: compilation failed for package 'glue'
* removing '/usr/local/lib/R/site-library/glue'

The downloaded source packages are in
    '/tmp/Rtmpym9Dy9/downloaded_packages'

【问题讨论】:

    标签: python r bash subprocess


    【解决方案1】:

    您显然通过提供自己的环境带走了PATH 的(有用的价值)。如果您想像 shell 一样,只需对您继承的环境进行最小必要的更改。

    【讨论】:

      猜你喜欢
      • 2015-08-15
      • 2017-10-17
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 1970-01-01
      • 2018-06-01
      相关资源
      最近更新 更多