当试图用熊猫试试pytest时的Keyerror

时间:2018-04-27 21:56:26

标签: python python-3.x pandas machine-learning pytest

嗨,所有的机器学习和python专家。我寻求你的帮助。

我最近看到谷歌毫升速成课程。他们建议在开始速成课程之前熟悉大熊猫。

所以,我已经使用python v3.5.2和pip的pandas安装了pip v8.1.1。并且还使用pip安装了pytest 3.5.1。

但是当我尝试使用pandas installation page文档中提供的推荐测试套件时,我遇到了错误。

user@host:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.test()
running: pytest --skip-slow --skip-network /home/ashraf/.local/lib/python3.5/site-packages/pandas
==================================================================== test session starts ====================================================================
platform linux -- Python 3.5.2, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /home/user, inifile:
collected 0 items / 1 errors                                                                                                                                

========================================================================== ERRORS ===========================================================================
_____________________________________________________________________ ERROR collecting  _____________________________________________________________________
.local/lib/python3.5/site-packages/_pytest/config.py:334: in _getconftestmodules
    return self._path2confmods[path]
E   KeyError: local('/home/user/.local/lib/python3.5/site-packages/pandas/tests/io')

During handling of the above exception, another exception occurred:
.local/lib/python3.5/site-packages/_pytest/config.py:365: in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local('/home/user/.local/lib/python3.5/site-packages/pandas/tests/io/conftest.py')

During handling of the above exception, another exception occurred:
.local/lib/python3.5/site-packages/_pytest/config.py:371: in _importconftest
    mod = conftestpath.pyimport()
.local/lib/python3.5/site-packages/py/_path/local.py:668: in pyimport
    __import__(modname)
.local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py:213: in load_module
    py.builtin.exec_(co, mod.__dict__)
.local/lib/python3.5/site-packages/pandas/tests/io/conftest.py:3: in <module>
    import moto
E   ImportError: No module named 'moto'

During handling of the above exception, another exception occurred:
.local/lib/python3.5/site-packages/py/_path/common.py:377: in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
.local/lib/python3.5/site-packages/py/_path/common.py:429: in gen
    for p in self.gen(subdir):
.local/lib/python3.5/site-packages/py/_path/common.py:418: in gen
    dirs = self.optsort([p for p in entries
.local/lib/python3.5/site-packages/py/_path/common.py:419: in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
.local/lib/python3.5/site-packages/_pytest/main.py:434: in _recurse
    ihook = self.gethookproxy(path)
.local/lib/python3.5/site-packages/_pytest/main.py:338: in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
.local/lib/python3.5/site-packages/_pytest/config.py:348: in _getconftestmodules
    mod = self._importconftest(conftestpath)
.local/lib/python3.5/site-packages/_pytest/config.py:376: in _importconftest
    raise ConftestImportFailure(conftestpath, sys.exc_info())
E   _pytest.config.ConftestImportFailure: ImportError("No module named 'moto'",)
E     File "/home/user/.local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py", line 213, in load_module
E       py.builtin.exec_(co, mod.__dict__)
E     File "/home/user/.local/lib/python3.5/site-packages/pandas/tests/io/conftest.py", line 3, in <module>
E       import moto
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================== 1 error in 0.59 seconds ==================================================================

现在,我该如何修复它,我可能做错了什么或丢失任何包裹?请帮助我。

1 个答案:

答案 0 :(得分:1)

要在pandas中运行测试,您需要安装大量development requirements

pip install -U [--user] ci/requirements_dev.txt