rpy2 can not import R package with rJava--mac
<p>I want to use rpy2 import R package 'iqspr' which I have aleady installed and test on my Rstudio, this package works fine. </p>

<p>Here are the errors I am getting.</p>

<pre><code>from rpy2.robjects.packages import importr

java=importr('rJava')
iqspr=importr('iqspr')
</code></pre>

<p>errors </p>

<pre><code>/Library/Python/2.7/site-packages/rpy2-2.8.3-py2.7-macosx-10.11-intel.egg/rpy2/rinterface/__init__.py:185: RRuntimeWarning: Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so':
  dlopen(/usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so
  Reason: image not found

  warnings.warn(x, RRuntimeWarning)
/Library/Python/2.7/site-packages/rpy2-2.8.3-py2.7-macosx-10.11-intel.egg/rpy2/rinterface/__init__.py:185: RRuntimeWarning: Error: .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so':
  dlopen(/usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so
  Reason: image not found

  warnings.warn(x, RRuntimeWarning)
Traceback (most recent call last):
  File "/Users/yang/Desktop/Chemical compounds design important materials/chemical_compound_design.py", line 4, in &lt;module&gt;
    java=importr('rJava')
  File "/Library/Python/2.7/site-packages/rpy2-2.8.3-py2.7-macosx-10.11-intel.egg/rpy2/robjects/packages.py", line 453, in importr
    env = _get_namespace(rname)
rpy2.rinterface.RRuntimeError: Error: .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so':
  dlopen(/usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /usr/local/lib/R/3.3/site-library/rJava/libs/rJava.so
  Reason: image not found
</code></pre>

<p>Issues involving RStudio and rJava were reported in the past (for example <a href="http://stackoverflow.com/questions/30738974/rjava-load-error-in-rstudio-r-after-upgrading-to-osx-yosemite">rJava load error in RStudio/R after &quot;upgrading&quot; to OSX Yosemite</a>), and it is quite possible that the cause is similar.</p>

<p>Try doing</p>

<pre><code>export LD_LIBRARY_PATH=/usr/local/lib/R/3.3/site-library/rJava/libs/:{LD_LIBRARY_PATH}
</code></pre>

<p>before starting Python.</p>

python rpy2 rjava