Importing matplotlib with reticulate in R Importing matplotlib with reticulate in R r r

Importing matplotlib with reticulate in R


I was able to get things working by changing the R Markdown code block to read:

```{r}library(reticulate)use_python('/usr/bin/python3')``````{python}import matplotlib.pyplot as plt```

I still don't really understand why, but it seems that reticulate doesn't play nice with anaconda installations. Maybe it has something to do with anaconda being set up to work well with an interactive Jupyter notebook.


I was able to get it to work with my conda install by sym linking the conda lib file to /lib/x86_64-linux-gnu/.

ln -s -f /opt/miniconda/lib/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1

I noticed that if I ran python alone with the same import it worked fine. It appears that reticulate isn't 'seeing' the conda lib as a source for libz but does look in the /lib/x86_64-linux-gnu/ directory.

Python: 3.6
Conda: 4.5.1
OS: Ubuntu 14.04.1 LTS


I found the same error with reticulate, which is not reading the zlib from the anaconda library but from /lib/x86_64-linux-gnu/.

Instead of symlinking, I just run the following line from terminal each time I'm using the script:

export LD_LIBRARY_PATH=/home/craig/anaconda3/lib/:$LD_LIBRARY_PATH

You can actually run it from inside the R script, giving:

system('export LD_LIBRARY_PATH=/home/craig/anaconda3/lib/:$LD_LIBRARY_PATH')