Python ';没有模块';使用Nosetests的目录中的_init__uuu.py出错
我有以下目录结构:Python ';没有模块';使用Nosetests的目录中的_init__uuu.py出错,python,python-2.7,import,python-module,Python,Python 2.7,Import,Python Module,我有以下目录结构: Chippa/ bin/ __init__.py app.py tests/ __init__.py app_tests.py tools.py templates/ hello_form.html index.html layout.html docs/ 在我的app_tes
Chippa/
bin/
__init__.py
app.py
tests/
__init__.py
app_tests.py
tools.py
templates/
hello_form.html
index.html
layout.html
docs/
在我的app_tests.py
文件中,我有:
from nose.tools import *
from bin.app import app
from tests.tools import assert_response
当我尝试从tests
目录外运行app\u tests.py
时,在Chippa
目录内的测试目录上方一级,如下所示:
python tests/app_tests.py
我得到以下错误:
Traceback (most recent call last):
File "tests/app_tests.py", line 3, in <module>
from bin.app import app
ImportError: No module named bin.app
回溯(最近一次呼叫最后一次):
文件“tests/app_tests.py”,第3行,在
从bin.app导入应用程序
ImportError:没有名为bin.app的模块
但是我在
bin
目录中确实有一个空的\uuu init\uuuuuuuuuuuuuupy
,我认为这会阻止这个问题。我错过了什么 要使导入工作,首先必须实际运行一个适当的模块。所以,而不是
python tests/app_tests.py
,试试看
尝试了
python-m test.app_tests
并获得:python-m test.app_tests/Library/Frameworks/python.framework/Versions/2.7/Resources/python.app/Contents/MacOS/python:没有名为test.app_tests的模块,对不起。@minitech您能解释一下这两个命令的区别吗?我经常遇到导入错误,要么通过“-m”解决,要么使用来自未来导入绝对导入的(最常见的情况是使用scrapy
——web爬行框架)。如果你能建议我好好阅读一下import是如何工作的,或者任何能让我避免此类错误的东西,那就太好了。
python -m tests.app_tests