I just started using the reticulate package in R, and I'm still getting a few of the kinks figured out. In particular, importing matplotlib is not going well. I've tried it two different ways, with different error messages for each.
First, using repl_python in RStudio's interactive shell:
library(reticulate)
use_python('/home/craig/anaconda3/bin/python')
py_discover_config()
repl_python()
import matplotlib.pyplot as plt
The REPL Python shell that opens up seems to have the correct version and everything, but when I try to import matplotlib.pyplot, I see the following:
ImportError: /lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/../../.././libpng16.so.16)
Installing zlib (using sudo apt-get install lib64z1-dev lib64z1
) didn't seem to change anything. FWIW, import matplotlib
worked just fine, as long as I don't need pyplot
.
I also tried doing the same thing in an R Markdown document:
```{r}
library(reticulate)
py_discover_config()
```
```{python}
import matplotlib.pyplot as plt
```
This time I saw:
Error in py_get_attr_impl(x, name, silent): AtributeError: module 'matplotlib' has no attribute 'pyplot' Calls: ... $.python.builtin.object -> py_get_attr -> py_get_attr_impl -> .Call Execution halted
Any ideas what might be going on here?
Thanks!
UPDATE: As I mentioned in the comments, installing the developer version of reticulate fixes some of the problems, but not all. If I try to run this Rmd:
```{r}
library(reticulate)
use_python('/home/craig/anaconda3/bin/python')
```
```{python}
import matplotlib.pyplot as plt
```
I get the following error messages:
Error in py_run_string_impl(code, local, convert) :
ImportError: /home/craig/anaconda3/lib/python3.6/site-packages/PyQt5/../../../libxcb-dri3.so.0: undefined symbol: xcb_send_request_with_fds
Detailed traceback:
File "<string>", line 1, in <module>
File "/home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "/home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import (
File "/home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 18, in <module>
import matplotlib.backends.qt_editor.figureoptions as figureoptions
File "/home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 20, in <module>
Calls: <Anonymous> ... force -> py_run_string -> py_run_string_impl -> .Call
Execution halted
When I tried googling the error text, a similar error with xcb does seem to be coming up in a context that is, as far as I can tell, not so relevant.
matplotlib
rather thanmatplotlib.pyplot
. Importingmatplotlib
sans pyplot using`repl_python()
rather than R Markdown gives no error. – Storzrepl_python()
error by following the instructions here: #48307349 – Storzdevtools::install_github("rstudio/reticulate")
helps a little (i.e. I can nowimport matplotlib
without an error), but I'm still getting errors when I try toimport matplotlib.pyplot
. – Storz