Home > Software engineering >  python in Rmarkdown using reticulate cannot read packages
python in Rmarkdown using reticulate cannot read packages

Time:04-25

I am using R on a MacBook. I have an Rmarkdown document and I'm trying to use reticulate in order to use python within R.

First I download the libraries:

```{r libraries, warning = FALSE, message = FALSE}

library(dplyr)
library(reticulate)

```

Next I look at an R chunk and figure out my working directory. Then I write mtcars to my desktop.

```{r chunk, warning = FALSE, message = FALSE}

getwd()

write.csv(mtcars, '/Users/name/Desktop/mtcars.csv', row.names = TRUE)

```

Then I try to use python instead to read in that csv that I just wrote to my desktop.

```{python}

import pandas as pd

mtcars = pd.read_csv('/Users/name/Desktop/mtcars.csv')

```

But I get this error:

ModuleNotFoundError: No module named 'pandas'
NameError: name 'pd' is not defined

So I went to this enter image description here

  • Related