2

I'm am trying to import some python modules from my virtualenv that I created, within a Rmarkdown document. I am new to python, so I'll just walk through the steps of my setup.

(1) I created a new virtualevn called r-reticulate in the default root location ~/.virtualenvs using

virtualenv -p /usr/bin/python3 r-reticulate

(2) After activating the env, I installed a few modules using pip. The follwing is a list of the installed packages:

$ pip list

Package         Version
--------------- -------
cycler          0.10.0
kiwisolver      1.0.1
matplotlib      3.0.2
numpy           1.16.1
pandas          0.24.1
pip             19.0.3
pkg-resources   0.0.0
pyparsing       2.3.1
python-dateutil 2.8.0
pytz            2018.9
setuptools      40.8.0
six             1.12.0
virtualenv      16.4.1
wheel           0.33.1

(3) Now to my R code. I have 2 only code chunks. The first:

```{r}
library(reticulate)
use_virtualenv(virtualenv = "r-reticulate")
```

and the second:

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

The first code chuck runs without error, but the second one returns:

ImportError: No module named matplotlib

I've verified that the r-reticulate environment does work, by activating it and importing thes modules through the terminal.


Sesssion Info

R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reticulate_1.10 ggplot2_3.1.0 
Rob A
  • 63
  • 5

1 Answers1

1

After more digging, I noticed that I didn't have the latest version of reticulate. Upgrading to reticulate_1.9 appears to have resolved module import error. I was successful in importing other packages from my r-reticulate env, so I believe that it use_virtualenv(virtualenv = "r-reticulate") is working correctly now.

Rob A
  • 63
  • 5
  • Updating to latest CRAN didn't work for me, but updating to latest Github worked. I don't know why. Whoever needs to do so, can run: `devtools::install_github("rstudio/reticulate")` – CoderGuy123 Oct 20 '20 at 03:00