首页 > 解决方案 > How to choose the environment in a python chunk in rmarkdown

问题描述

I try to get familiar with python in R. I made it work using reticulate along the following lines:

library(reticulate)
py_install("pandas")

Then I can always get back to the enviroment where I installed that to using

use_condaenv("r-reticulate")

How can I use this in a python chunk of the following form

```{python}
import pandas as pd
```

pandas can be found in the first version above (using reticulate) but not in the version with the python chunk. How can I tell it to use the "r-reticulate" environment? Setting it in an R set-up chunk in the following form does not work for me

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(reticulate)
use_condaenv("r-reticulate")
```

标签: pythonr-markdownreticulate

解决方案


I had the same issue, it was fixed by setting the required keyword to TRUE.

use_condaenv(condaenv='env-name', required = TRUE)


推荐阅读