rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.67k stars 327 forks source link

Problems knitting a .Rmd file with reticulate using python from a conda env #1032

Open bv2 opened 3 years ago

bv2 commented 3 years ago

Hi,

I am not able to knit an Rmd file that uses reticulate when using a Python version from a conda environment.

For example: The following .Rmd file stops during the knitting process without any error in the first chunk. It only occurs when knitting the file, I can run the code of each chunk without any problems. Also I am able to knit the file if I comment the first line (reticulate::use_python("/opt/anaconda3/envs/mofa/bin/python")).

---
title: "Example"
---
```{r}
reticulate::use_python("/opt/anaconda3/envs/my_env/bin/python")
reticulate::py_config()
sessionInfo()

Do you have any suggestions what could be the problem?
This is my sessionInfo:

R version 4.1.0 (2021-05-18)

Platform: x86_64-apple-darwin17.0 (64-bit)

Running under: macOS Big Sur 10.16

Matrix products: default

BLAS: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.dylib

LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:

[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:

[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):

[1] Rcpp_1.0.7 lattice_0.20-44 png_0.1-7 digest_0.6.27

[5] grid_4.1.0 R6_2.5.0 jsonlite_1.7.2 magrittr_2.0.1

[9] evaluate_0.14 rlang_0.4.11 stringi_1.7.3 jquerylib_0.1.4

[13] Matrix_1.3-4 bslib_0.2.5.1 reticulate_1.20 rmarkdown_2.9

[17] tools_4.1.0 stringr_1.4.0 xfun_0.24 yaml_2.2.1

[21] compiler_4.1.0 htmltools_0.5.1.1 knitr_1.33 sass_0.4.0

kevinushey commented 3 years ago

Some questions that will help narrow down the issue:

bv2 commented 3 years ago

Hi @kevinushey , thanks for taking a look at this problem. Here some more details:

kevinushey commented 3 years ago

it happens when rendering the file via the Knit button. Using rmarkdown::render() works fine, while devtools::build() to build html vignettes inside a package also does not work.

Do you see this issue if you run devtools::build() from the command line; e.g. in a plain R session outside of RStudio? Any chance you can share the package sources in case I'm able to reproduce in that context?

bv2 commented 3 years ago

The package built issue also appears from the command line but I am mostly wondering about the problem with a simple example as above when using the Knit button.

Prior to my last update of R (to R4.1) this always worked fine. Could this be specific to the combination of being on a Mac (10.16), using R 4.1 and having reticulate configured to use a conda environment? Or is this related to something in my personal setup I would have to change?