简体   繁体   中英

How to `pip install` Python module in RStudio?

Hoping for some help. How does one pip install a Python package for reticulating from within an RStudio R-Markdown ( .Rmd ) file?

For example, the lasio Python package is not available through conda . Hence, the following .Rmd code was not able to add the package to my environment:

```{r}
library(reticulate)
py_install("lasio")    # did not work
```

I also tried to install the package with Python code (to no avail):

```{python}
import sys
!{sys.executable} -m install lasio    # did not work

$ python -m pip install lasio    # also did not work
```

Turns out that the lasio package could be installed/added to my environment by typing pip install lasio in RStudio's Terminal window/tab. However, I'm hoping for code that can be run with .R or .Rmd code so as to automate the process when ported to another machine. Thanks.

py_install() has a pip argument that you can set to TRUE which should use pip to install your module:

py_install("lasio",pip=TRUE)

Alternatively, you can use system2() to pass calls directly into the terminal.

system2("pip install lasio")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM