本文介绍了将pypy2与numpy.testing一起使用时的ImportError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用numpy.testing模块进行单元测试时,我遇到了一个非常奇怪的错误.我正在VM中运行iPython笔记本.在我的代码中,我进行了一个测试,将我的输出与R中的输出进行比较.这需要我像下面这样加载rpy2模块:

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')

但是,当我运行! py.test时,出现以下错误:

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)如果创建了先前版本,则删除__pycache__目录

1) delete __pycache__ directory if a previous version was created

2)在命令行中的anaconda中安装readline:conda install -c asmeurer readline

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

3).py文件中包含import readline

3) Inside the .py file include import readline

这篇关于将pypy2与numpy.testing一起使用时的ImportError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:25