ImportError when using rpy2 with numpy.testing

痞子三分冷 提交于 2019-12-05 02:44:29

问题


I've run into a rather strange error when doing unit testing with the numpy.testing module. I'm running an iPython notebook in a VM. In my code, I have one test where I compare my output to that in R. This requires me to load the rpy2 modules like so:

import rpy2.robjects as robjects
from rpy2.robjects.packages import importr
fastclime = importr('fastclime')
grdevices = importr('grDevices')

However when I run ! py.test, I get the following error:

==================================== ERRORS ====================================

_____________________ ERROR collecting test_fastclime_R.py _____________________
test_fastclime_R.py:6: in <module>
    import rpy2.robjects as robjects
../../anaconda/lib/python2.7/site-packages/rpy2/robjects/__init__.py:15: in <module>
    import rpy2.rinterface as rinterface
../../anaconda/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:101: in <module>
    from rpy2.rinterface._rinterface import *
E   ImportError: /home/bitnami/anaconda/bin/../lib/libreadline.so.6: undefined symbol: PC
====================== 10 passed, 1 error in 0.19 seconds ======================

I suspect that this has something to do with some environment variable not being linked to my working directory, but I have no idea how to fix it. Any suggestions are greatly appreciated! Thank you!


回答1:


The solution was to

1) delete __pycache__ directory if a previous version was created

2) Install readline in anaconda in the command line: conda install -c asmeurer readline

3) Inside the .py file include import readline




回答2:


another solution is to remove conda's readline from the environment and to use pip's one:

conda remove --force readline
pip install readline


来源:https://stackoverflow.com/questions/29944238/importerror-when-using-rpy2-with-numpy-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!