Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试使用pandas测试套件pytest时出现Keyerror_Python_Python 3.x_Pandas_Machine Learning_Pytest - Fatal编程技术网

Python 尝试使用pandas测试套件pytest时出现Keyerror

Python 尝试使用pandas测试套件pytest时出现Keyerror,python,python-3.x,pandas,machine-learning,pytest,Python,Python 3.x,Pandas,Machine Learning,Pytest,大家好,这里有所有的机器学习和python专家。我寻求你的帮助 我最近看过谷歌ml速成班。他们建议在开始速成班之前先熟悉熊猫 因此,我使用PythonV3.5.2和pip中的pandas安装了PIPV8.1.1。还使用pip安装了pytest 3.5.1 但是当我尝试使用pandas文档中给出的推荐测试套件时,我遇到了错误 user@host:~$ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609

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

我最近看过谷歌ml速成班。他们建议在开始速成班之前先熟悉熊猫

因此,我使用PythonV3.5.2和pip中的pandas安装了PIPV8.1.1。还使用pip安装了pytest 3.5.1

但是当我尝试使用pandas文档中给出的推荐测试套件时,我遇到了错误

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 ==================================================================
user@host:~$python3
Python 3.5.2(默认值,2017年11月23日,16:37:01)
[GCC 5.4.0 20160609]在linux上
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>作为pd进口熊猫
>>>pd.测试()
运行:pytest--跳过慢速--跳过network/home/ashraf/.local/lib/python3.5/site-packages/pandas
===================================================================================================测试会话开始====================================================================
平台linux——Python 3.5.2、pytest-3.5.1、py-1.5.3、pluggy-0.6.0
rootdir:/home/user,文件:
已收集0项/1个错误
===================================================================================================错误===========================================================================
_____________________________________________________________________错误收集_____________________________________________________________________
.local/lib/python3.5/site-packages/_-pytest/config.py:334:in _-getconftestmodules
返回自我。\u路径2confmods[path]
E KeyError:local('/home/user/.local/lib/python3.5/site-packages/pandas/tests/io'))
在处理上述异常期间,发生了另一个异常:
.local/lib/python3.5/site packages/\u pytest/config.py:365:in\u importconftest
返回self.\u conftestpath2mod[conftestpath]
E KeyError:local('/home/user/.local/lib/python3.5/site packages/pandas/tests/io/conftest.py'))
在处理上述异常期间,发生了另一个异常:
.local/lib/python3.5/site packages/\u pytest/config.py:371:in uImportOffTest
mod=conftestpath.pyimport()
.local/lib/python3.5/site-packages/py/_-path/local.py:668:in-pyimport
__导入(modname)
.local/lib/python3.5/site-packages/_-pytest/assertion/rewrite.py:213:in-load_模块
py.内置执行器(公司、模块、指令)
.local/lib/python3.5/site packages/pandas/tests/io/conftest.py:3:in
进口摩托车
E:没有名为“moto”的模块
在处理上述异常期间,发生了另一个异常:
.local/lib/python3.5/site packages/py/_path/common.py:377:访问中
对于访客中的x(fil、rec、ignore、bf、sort)。gen(self):
.local/lib/python3.5/site-packages/py/_-path/common.py:429:in-gen
对于self.gen(subdir)中的p:
.local/lib/python3.5/site-packages/py/_-path/common.py:418:in-gen
dirs=self.optsort([p代表条目中的p
.local/lib/python3.5/site packages/py/_path/common.py:419:in
如果p.check(dir=1)和(rec为None或rec(p))])
.local/lib/python3.5/site packages/\u pytest/main.py:434:in\u recurse
ihook=self.gethookproxy(路径)
.local/lib/python3.5/site-packages/_-pytest/main.py:338:in-gethookproxy
my_conftestmodules=pm.\u getconftestmodules(fspath)
.local/lib/python3.5/site-packages/_-pytest/config.py:348:in _-getconftestmodules
mod=self.\u importconftest(conftestpath)
.local/lib/python3.5/site packages/\u pytest/config.py:376:in\u importconftest
引发ConftestImportFailure(conftestpath,sys.exc_info())
E _pytest.config.ConftestImportFailure:ImportError(“没有名为“moto”的模块,)
加载模块中的E文件“/home/user/.local/lib/python3.5/site packages/\u pytest/assertion/rewrite.py”,第213行
E-py.内置执行器(公司,国防部)
E文件“/home/user/.local/lib/python3.5/site packages/pandas/tests/io/conftest.py”,第3行,在
进口摩托车
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 中断:收集过程中出现1个错误!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================================================================0.59秒内出现1个错误==================================================================

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

要在pandas中运行测试,您需要安装很多:


pip安装moto
?但后来出现了moto错误。首先,它在config.py文件中显示了一些keyerror。我不知道moto未安装是否是错误的主要原因。
moto
未安装是错误的主要原因。Rest只是由于未解析的导入而在
conftest
加载时崩溃。好的,让我尝试安装它。应该使用-U标志来安装moto,比如
pip install-U moto
,因为我在安装pytest时使用了U标志。经验法则:遇到问题时,始终
pip install--user
pip install -U [--user] ci/requirements_dev.txt