Oleksandr Yarushevskyi
Oleksandr Yarushevskyi

Reputation: 3289

Python subprocess.check_call works in a different way than bash

I'm trying to run Rscript via Python using subprocess.check_call.

Rscript is very simple it just checks if Rpackage exists, and if not it installs it.

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

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

When I run such command in bash

Rscript packages.R

it works fine.

But when I tried to run it using subprocess.check_call

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

I got such error:

* 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'

Upvotes: 1

Views: 57

Answers (1)

Davis Herring
Davis Herring

Reputation: 39868

You evidently took away (the useful value for) PATH by providing your own environment. If you want to be like the shell, make only the minimum necessary changes to the environment you inherit.

Upvotes: 1

Related Questions