title: Importing matplotlib with reticulate in R
body: <p>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.</p>
  
  <p>First, using repl_python in RStudio's interactive shell:</p>
  
  <pre><code>library(reticulate)
  use_python('/home/craig/anaconda3/bin/python')
  py_discover_config()
  repl_python()
  import matplotlib.pyplot as plt
  </code></pre>
  
  <p>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:</p>
  
  <p>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)</p>
  
  <p>Installing zlib (using <code>sudo apt-get install lib64z1-dev lib64z1</code>) didn't seem to change anything. FWIW, <code>import matplotlib</code> worked just fine, as long as I don't need <code>pyplot</code>.</p>
  
  <p>I also tried doing the same thing in an R Markdown document:</p>
  
  <pre><code>```{r}
  library(reticulate)
  py_discover_config()
  ```
  
  ```{python}
  import matplotlib.pyplot as plt
  ```
  </code></pre>
  
  <p>This time I saw:</p>
  
  <p>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</p>
  
  <p>Any ideas what might be going on here?</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE:</strong> 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:</p>
  
  <pre><code>```{r}
  library(reticulate)
  use_python('/home/craig/anaconda3/bin/python')
  ```
  
  ```{python}
  import matplotlib.pyplot as plt
  ```
  </code></pre>
  
  <p>I get the following error messages:</p>
  
  <pre><code>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 "&lt;string&gt;", line 1, in &lt;module&gt;
    File "/home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 116, in &lt;module&gt;
      _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 &lt;module&gt;
      from .backend_qt5 import (
    File "/home/craig/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py", line 18, in &lt;module&gt;
      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 &lt;module&gt;
  Calls: &lt;Anonymous&gt; ... force -&gt; py_run_string -&gt; py_run_string_impl -&gt; .Call
  Execution halted
  </code></pre>
  
  <p>When I tried googling the error text, a <a href="https://github.com/ValveSoftware/steam-for-linux/issues/5249" rel="noreferrer">similar error with xcb</a> does seem to be coming up in a context that is, as far as I can tell, not so relevant.</p>