无法在拆分命名空间中找到模块

时间:2013-07-26 20:04:09

标签: python python-3.x pytest

我正在使用Python 3.3.1 64位在Ubuntu 13.04 64位上运行Eclipse 4.3 64位,并在Pydev 2.7.6环境中使用virtualenv运行Dictionary | ---------------------------- | | src test | | petaapan petaapan | | | | __init__.py logging __init__.py logging | | | | __init__.py mplogging.py __init__.py test_mplogging.py 64位。我的项目在以下目录结构中。

test_mplogging.py

当我尝试使用pytest作为测试运行器运行pydev debugger: starting ============================= test session starts ============================== platform linux -- Python 3.3.1 -- pytest-2.3.5 plugins: pep8, cache collected 0 items / 1 errors ==================================== ERRORS ==================================== ______________________ ERROR collecting test_mplogging.py ______________________ File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/test_mplogging.py", line 11 in <module> > import petaapan.logging.mplogging as ml E ImportError: No module named 'petaapan.logging.mplogging' 时,我得到以下结果:

sys.path

我的Dictionary/testDictionary/src之前__init__.py,因此首先搜索测试树,看起来这就是导入使用常规包失败的原因。

我的下一次尝试是使用命名空间包执行相同操作,因此我删除了所有pydev debugger: starting ============================= test session starts ============================== platform linux -- Python 3.3.1 -- pytest-2.3.5 plugins: pep8, cache collected 0 items / 1 errors ==================================== ERRORS ==================================== ______________________ ERROR collecting test_mplogging.py ______________________ File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/test_mplogging.py", line 11 in <module> > import petaapan.logging.mplogging as ml File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/<frozen importlib._bootstrap>", line 1564 in _find_and_load > ??? File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/<frozen importlib._bootstrap>", line 1522 in _find_and_load_unlocked > ??? File "/home/jonathan/UC/Git Repositories/isiiwesuu/Dictionary/tests/petaapan/logging/<frozen importlib._bootstrap>", line 1476 in _find_module > ??? File "/home/jonathan/isiiwesuu/lib/python3.3/site-packages/_pytest/assertion/rewrite.py", line 68 in find_module > fd, fn, desc = imp.find_module(lastname, path) File "/home/jonathan/isiiwesuu/lib/python3.3/imp.py", line 197 in find_module > "not {}".format(type(name))) E RuntimeError: 'list' must be None or a list, not <class 'str'> =========================== 1 error in 0.49 seconds ============================ 文件并获得了以下结果:

test_mplogging.py

以下是import logging from os import getcwd from multiprocessing import Queue, Process import petaapan.logging.mplogging as ml 相关部分:

{{1}}

在这种情况下,有人可以建议我需要做什么吗?

1 个答案:

答案 0 :(得分:0)

我可以看到petaapan.logging.mploggingDictionary/src Dictionary/test,但petaapan下没有。{/ p>

我相信解释器会从import指令中解析Dictionary/test并在mplogging中找到它,然后建议它是您引用的模块。但之后它无法在Dictionary/test/petaapan/logging中找到{{1}}(在检测到的模块范围内),从而引发异常。