Search code examples
pythonrinstallationrpy2

rpy2 not finding include directory


At install of the rpy2 package with command: python setup.py build install , the install process throws the following error.

I've configured two environment variables, pointing to the missing file.

export R_HOME=/data/myprojects/R/R-devel
export R_INCLUDE_DIR=/data/myprojects/R/R-devel/include

python setup.py build install
setup.py:29: UserWarning: R emitting a warning: WARNING: ignoring environment value of R_HOME
  warnings.warn("R emitting a warning: %s" % r_home[0])
setup.py:130: UserWarning: R emitting a warning: WARNING: ignoring environment value of R_HOME
  warnings.warn("R emitting a warning: %s" % rversion)
R version 3.3.0 Patched (2016-05-05 r70590) -- "Supposedly Educational"
/data/myprojects/R/R-patched/bin/R CMD config --ldflags
R was not built as a library
setup.py:155: UserWarning: R emitting a warning: WARNING: ignoring environment value of R_HOME
  warnings.warn("R emitting a warning: %s" % output[0])
/data/myprojects/R/R-patched/bin/R CMD config --cppflags
R was not built as a library
setup.py:211: UserWarning: No include specified
  warnings.warn('No include specified')
setup.py:222: UserWarning: No libraries as -l arguments to the compiler.
  warnings.warn('No libraries as -l arguments to the compiler.')

    Compilation parameters for rpy2's C components:
        include_dirs    = []
        library_dirs    = []
        libraries       = []
        extra_link_args = []

running build
running build_py
running build_clib
building 'r_utils' library
gcc -pthread -fno-strict-aliasing -fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -fstack-protector -O2 -Wall -D_FORTIFY_SOURCE=2 -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -I./rpy/rinterface -c ./rpy/rinterface/r_utils.c -o build/temp.linux-s390x-2.7/./rpy/rinterface/r_utils.o
./rpy/rinterface/r_utils.c:31:22: fatal error: Rdefines.h: No such file or directory
 #include <Rdefines.h>
                      ^
compilation terminated.
error: command 'gcc' failed with exit status 1

Question: How to fix the configuration for the setup.py process to find the include headers.


Solution

  • The key hint in the output is:

    R was not built as a library
    

    R must be built as a shared library in order for rpy2 to be able to use that shared library (see the notes here: http://rpy2.readthedocs.io/en/version_2.7.x/overview.html#using-rpy2-with-other-versions-of-r-or-python ).