我尝试使用以下命令在R 3.1.1的计算机上安装rpy2:
pip install rpy2 --user
它输出成功,但是当我尝试使用
进行测试时python -m rpy2.tests
它给我以下错误
File "/mnt/work1/software/python/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/mnt/work1/software/python/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/mnt/work1/users/home2/stamaki/.local/lib/python2.7/site-packages/rpy2-2.6.0-py2.7-linux-x86_64.egg/rpy2/tests.py", line 23, in <module>
import rpy2.tests_rpy_classic
File "/mnt/work1/users/home2/stamaki/.local/lib/python2.7/site-packages/rpy2-2.6.0-py2.7-linux-x86_64.egg/rpy2/tests_rpy_classic.py", line 3, in <module>
import rpy2.rpy_classic as rpy
File "/mnt/work1/users/home2/stamaki/.local/lib/python2.7/site-packages/rpy2-2.6.0-py2.7-linux-x86_64.egg/rpy2/rpy_classic.py", line 5, in <module>
import rpy2.rinterface as ri
File "/mnt/work1/users/home2/stamaki/.local/lib/python2.7/site-packages/rpy2-2.6.0-py2.7-linux-x86_64.egg/rpy2/rinterface/__init__.py", line 100, in <module>
from rpy2.rinterface._rinterface import *
ImportError: /mnt/work1/users/home2/stamaki/.local/lib/python2.7/site-packages/rpy2-2.6.0-py2.7-linux-x86_64.egg/rpy2/rinterface/_rinterface.so: undefined symbol: R_ClassSymbol
它似乎是在环境变量中没有设置R的C包含路径的情况,因为sexp.c
的编译不包括来自R文件夹的Rinternals.h
,其中{ {1}}已定义
但是在R_ClassSymbol
我确实设置了以下内容:
export C_INCLUDE_PATH =&#34; /mnt/work1/software/R/3.1.1/lib64/R/include:$ {C_INCLUDE_PATH}&#34;
export LD_LIBRARY_PATH =&#34; /mnt/work1/software/R/3.1.1/lib64/R/lib:$ {LD_LIBRARY_PATH}&#34;
所以我认为这个错误不应该发生。任何想法为什么会发生?
完整安装日志:
~/.bashrc
此外,请不要推荐我,无论如何需要sudo,如重新安装R,因为有时会被他人推荐。我没有系统的管理权限。
答案 0 :(得分:3)
在日志顶部附近,您会看到:R未构建为库。
R 必须编译为共享库才能使rpy2正常工作。