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!
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
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