【问题标题】:Keyerror when trying to testsuite pytest with pandas尝试使用熊猫测试套件 pytest 时出现键错误
【发布时间】:2018-10-08 19:03:52
【问题描述】:

大家好,所有机器学习和 Python 专家。我寻求你的帮助。

我最近看到了 google ml 速成课程。他们建议在开始速成课程之前先熟悉熊猫。

所以,我已经使用 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 ==================================================================

现在,我该如何解决它,我可能做错了什么或缺少任何包?请帮帮我。

【问题讨论】:

  • pip install moto?
  • 但后来出现了moto错误。起初,它在 config.py 文件中显示了一些 keyerror。不知道moto没有安装是不是这个错误的主要原因。
  • moto 未安装是该错误的主要原因。由于未解决的导入,Rest 只是 pytestconftest 加载时崩溃。
  • 好的,那我试试安装。应该使用 -U 标志来安装像 pip install -U moto 这样的 moto,因为我在安装 pytest 时使用了 U 标志。
  • 经验法则:有问题时,总是pip install --user

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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2020-11-03
    • 1970-01-01
    • 2015-08-27
    • 2023-04-01
    相关资源
    最近更新 更多