简体   繁体   English

如何在Ubuntu上安装和使用rpy2

[英]How to install and use rpy2 on Ubuntu

I am trying to use Python to call R through rpy2. 我正在尝试使用Python通过rpy2调用R。 I am working on Ubuntu 15.10. 我正在使用Ubuntu 15.10。 I have installed Python 3.5.1 as part of Anaconda 2.4.1 (64bit), R and rpy2 version 2.7.6. 我已经将Python 3.5.1安装为Anaconda 2.4.1(64位),R和rpy2版本2.7.6的一部分。 When I tried $ python -m 'rpy2.tests' on the terminal, I am getting the following error: 当我在终端上尝试$ python -m'rpy2.tests'时,出现以下错误:

Traceback (most recent call last):
  File "/home/thirsty/anaconda3/lib/python3.5/runpy.py", line 170, in    _run_module_as_main
    "__main__", mod_spec)
  File "/home/thirsty/anaconda3/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/thirsty/anaconda3/lib/python3.5/site-packages/rpy2/tests.py",   line 23, in <module>
    import rpy2.tests_rpy_classic
  File "/home/thirsty/anaconda3/lib/python3.5/site-packages/rpy2/tests_rpy_classic.py", line 3, in <module>
    import rpy2.rpy_classic as rpy
  File "/home/thirsty/anaconda3/lib/python3.5/site-packages/rpy2/rpy_classic.py", line 5, in <module>
    import rpy2.rinterface as ri
  File "/home/thirsty/anaconda3/lib/python3.5/site-packages/rpy2/rinterface/__init__.py", line 99, in <module>
    from rpy2.rinterface._rinterface import *
ImportError: /home/thirsty/anaconda3/bin/../lib/libreadline.so.6: undefined symbol: PC

I have resolved the issue. 我已经解决了这个问题。 The versions of python, rpy2 are fine. python,rpy2的版本都可以。 Probably the command $ python -m 'rpy2.tests' may not be right way of testing rpy2. 命令$ python -m'rpy2.tests'可能不是测试rpy2的正确方法。 After starting python shell, when I typed import rpy2.robjects as robjects it worked without any errors and I was able to read files using R. 启动python shell之后,当我输入import rpy2.robjects作为robjects时,它可以正常工作而没有任何错误,并且我能够使用R读取文件。

My server is not Ubuntu, but CentOS release 6.6 (Final). 我的服务器不是Ubuntu,而是CentOS 6.6版(最终版)。 I solved this problem with this way, I think you can find corresponding file in Ubuntu. 我用这种方式解决了这个问题,我想你可以在Ubuntu中找到相应的文件。

cp /lib64/libreadline.so.6 ~/anaconda3/lib/libreadline.so.6

Done. 做完了 Good luck. 祝好运。

But the way, if you can not install rpy2 and system tell you you need install Cython, then 但是,如果您无法安装rpy2并且系统告诉您需要安装Cython,那么

pip uninstall Cython
pip install Cython

Good luck Again 再次祝你好运

Again, don't install Anaconda2 and Anaconda3 in your server at the same time, just use any one of them and then change the environment. 同样,不要在您的服务器中同时安装Anaconda2和Anaconda3,仅使用其中之一,然后更改环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM