【发布时间】:2016-10-10 08:47:40
【问题描述】:
我有一个小的 python 模块
+-- address_book
| +-- models.py
| +-- __init__.py
+-- test
| +-- test_models.py
当我运行python address_book/test/test_models.py 时出现此错误
Traceback (most recent call last):
File "address_book/test/test_models.py", line 5, in <module>
from address_book import models
ImportError: No module named 'address_book'
test_models.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from address_book import models
...
...
...
if __name__ == '__main__':
unittest.main()
【问题讨论】:
-
你的树很奇怪。
__init__.py是文件,不是目录,对吧? -
@S.deMelo 我已经更新了树
-
您从哪个目录运行测试?您可能会发现
python address_book/test/test_models.py在python test_models.py不起作用的地方起作用。 -
@Dunes 都不起作用
标签: python