我有一个小的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'
测试模型.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from address_book import models
...
...
...
if __name__ == '__main__':
unittest.main()
请您参考如下方法:
你的文件结构应该是这样的
+-- address_book
| +-- __init__.py
| +-- models.py
+-- test
| +-- test_models.py
| +-- __init__.py
要使您的代码正常工作,您还必须位于 address_book 之上的目录中。
