Python subprocess.check_call与bash的工作方式不同

问题描述 投票:1回答:1

我正在尝试使用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'

我正在尝试使用subprocess.check_call通过Python运行Rscript。 Rscript非常简单,它仅检查Rpackage是否存在,如果不存在,则将其安装。 local({r

python r bash subprocess
1个回答
0
投票

您显然通过提供自己的环境而夺走了PATH的有用价值。如果要像外壳一样,请仅对继承的环境进行最少的必要更改。

© www.soinside.com 2019 - 2024. All rights reserved.