我有以下目录结构。
$ tree emaildiff/
|____
| |______init__.py
| |______init__.pyc
| |____mail
| | |____.DS_Store
| | |______init__.py
| | |______init__.pyc
| | |____send.py
| | |____send.pyc
| |____maildiff_cmd.py
| |____maildiff_cmd.pyc
| |____version.py
| |____version.pyc
我有两页代码为maildiff并发送
$ tree docs/source/
| |____
| | |_____static
| | |_____templates
| | |____conf.py
| | |____index.rst
| | |____maildiff.rst
| | |____send.rst
| | |____terminal.glue
基于
我有什么
.. automodule:: maildiff_cmd
:members:
:undoc-members:
:inherited-members:
:show-inheritance:
和send.py
.. automodule:: send
:members:
:undoc-members:
:inherited-members:
:show-inheritance:
在conf.py中我已经将python模块路径插入为
sys.path.insert(0, os.path.abspath('../../emaildiff'))
但是在做make html时我仍然得到错误
====================================
/Development/pyclones/git-maildiff/docs/source/maildiff.rst:13: WARNING: autodoc: failed to import module u'maildiff_cmd'; the following exception was raised:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object
__import__(self.modname)
File "/Development/pyclones/git-maildiff/emaildiff/maildiff_cmd.py", line 14, in <module>
import emaildiff.mail.send as send
ImportError: No module named emaildiff.mail.send
/Development/pyclones/git-maildiff/docs/source/send.rst:7: WARNING: Title underline too short.
下面的第二个错误:
Welcome to maildiff git command documentation!
====================================
/Development/pyclones/git-maildiff/docs/source/send.rst:13: WARNING: autodoc: failed to import module u'send'; the following exception was raised:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object
__import__(self.modname)
ImportError: No module named send
所以,如果我包括
sys.path.insert(1, os.path.abspath('../../emaildiff/mail'))
第二个错误消失了,为send.py生成了docs,但是emaildiff / mailddiff_cmd.py永远不会生成。
答案 0 :(得分:0)
我得到了它的工作,
我必须包含要显式插入的每个模块位置路径,即使我在实际模块旁边有__init__.py文件选址。
sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(1, os.path.abspath('../../emaildiff'))
sys.path.insert(2, os.path.abspath('../../emaildiff/mail'))