ImportError when using rpy2 with numpy.testing
While doing unit testing with the numpy.testing module, I ran into a rather strange error. I am running iPython notebook in a virtual machine. In my code, I have one test where I compare my output to the data in R. This requires me to load the rpy2 modules like this:
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 this is because some environment variable is not associated with my working directory, but I have no idea how to fix it. Any suggestions are greatly appreciated! Thank!
The solution was
1) delete the directory __pycache__
if a previous version was created
2) Install readline in anaconda on the command line:
conda install -c asmeurer readline
3) Inside the .py file there is import readline
another solution is to remove conda readline from the environment and use pip one:
conda remove --force readline
pip install readline