title: Use `rpy2` with packages installed for `R` in conda virtual environment?
body: <p>I have been trying to keep my environment non-redundant and clean so I made an <code>R</code> environment and wiped out all other existing <code>R</code>s on my computer.  </p>
  
  <p>That environment is called <code>r-conda</code> and it is in: </p>
  
  <p><code>/Users/jespinoz/anaconda/envs/r-conda/bin/R</code></p>
  
  <p>I realized I didn't have <code>rpy2</code> installed and to install it through conda it wanted to install the a new version of <code>R</code> and all of the <code>r-essentials</code> which I don't want since I already have a perfectly working R environment. </p>
  
  <p>I realized I could install <code>rpy2</code> for the <code>Python</code> associated within the <code>R conda</code> environment:</p>
  
  <pre><code>source activate r-conda
  pip install rpy2
  source deactivate
  </code></pre>
  
  <p>But not all of the paths are lined up</p>
  
  <p><strong>How can I make <code>rpy2</code> recognize all of my <code>R</code> associated files and paths in my <code>r-conda</code> environment?</strong> </p>
  
  <p>It's not finding the files correctly when I am trying to import packges: </p>
  
  <pre><code>os.environ['R_HOME'] = "/Users/jespinoz/anaconda/envs/r-conda/bin/R"
  from rpy2.robjects.packages import importr
  importr("dynamicTreeCut")
  
  ---------------------------------------------------------------------------
  ImportError                               Traceback (most recent call last)
  &lt;ipython-input-29-8b0a88dfe12d&gt; in &lt;module&gt;()
        1 # os.environ['R_HOME'] = '/Users/jespinoz/anaconda/envs/r-conda/bin/'
        2 os.environ['R_HOME'] = "/Users/jespinoz/anaconda/envs/r-conda/bin/R"
  ----&gt; 3 from rpy2.robjects.packages import importr
        4 importr("dynamicTreeCut")
  
  /Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/robjects/__init__.py in &lt;module&gt;()
       14 import itertools
       15 from datetime import datetime
  ---&gt; 16 import rpy2.rinterface as rinterface
       17 import rpy2.rlike.container as rlc
       18 
  
  /Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/__init__.py in &lt;module&gt;()
       90 del(os)
       91 
  ---&gt; 92 from rpy2.rinterface._rinterface import (baseenv,
       93                                          emptyenv,
       94                                          endr,
  
  ImportError: dlopen(/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so, 2): Library not loaded: @rpath/R/lib/libR.dylib
    Referenced from: /Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so
    Reason: image not found
  </code></pre>
  
  <p>Fixed that error by adding this to my <code>~/.bash_profile</code> but generated a similar new error:
  I gave this a try, and the error changed: </p>
  
  <pre><code>export LD_LIBRARY_PATH="/Users/jespinoz/anaconda/envs/r-conda/lib/R/lib/:$LD_LIBRARY_PATH" 
  
  &gt;&gt;&gt; from rpy2.robjects.packages import importr
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/robjects/__init__.py", line 16, in &lt;module&gt;
      import rpy2.rinterface as rinterface
    File "/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/__init__.py", line 92, in &lt;module&gt;
      from rpy2.rinterface._rinterface import (baseenv,
  ImportError: dlopen(/Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so, 2): Library not loaded: libicuuc.54.dylib
    Referenced from: /Users/jespinoz/anaconda/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so
    Reason: image not found
  </code></pre>
  
  <p>So I tried this, then got the same error: </p>
  
  <pre><code>export LD_LIBRARY_PATH="/Users/jespinoz/anaconda/envs/r-conda/lib/R/lib/:/Users/jespinoz/anaconda/pkgs/icu-54.1-0/lib/:$LD_LIBRARY_PATH"
  </code></pre>
  
  <p>If I use <code>conda install rpy2</code> it wants to install a <code>Python=3.5.2</code> even though my default version of my main conda environment is <code>Python=3.6</code>. @asmeurer gave a suggestion to specify <code>Python=3.6</code> when installing <code>rpy2</code> in my <code>r-conda</code> environment but now it's looking like a package conflicting error: </p>
  
  <pre><code>(r-conda) jespinozlt-osx:~ jespinoz$ conda install rpy2 python=3.6
  Fetching package metadata .............
  Solving package specifications: .
  
  
  UnsatisfiableError: The following specifications were found to be in conflict:
    - python 3.6*
    - r-permute
    - rpy2
  Use "conda info &lt;package&gt;" to see the dependencies for each package
  </code></pre>