Skip to main content
 首页 » 编程设计

python之rpy2 找不到包含目录

2024年10月24日8myhome

在使用命令安装 rpy2 包时: python setup.py build install ,安装过程抛出以下错误。

我配置了两个环境变量,指向丢失的文件。

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 

问题:如何修复 setup.py 进程的配置以查找包含 header 。

请您参考如下方法:

输出中的关键提示是:

R was not built as a library 

R 必须构建为共享库,以便 rpy2 能够使用该共享库(参见此处的注释:http://rpy2.readthedocs.io/en/version_2.7.x/overview.html#using-rpy2-with-other-versions-of-r-or-python)。