如何让Sphinx识别我的模块?

时间:2017-03-27 21:13:09

标签: python-3.x python-sphinx

我正在尝试学习如何使用Sphinx来记录Python代码,并且在识别我的模块和类来记录文档字符串时遇到了问题。我有一个简单的python类写入下面显示的Statistics.py文件,该文件存储在目录/Users/MyName/desktop/Code_Test/Test中。

import sys
sys.path.insert(0,"/Users/MyName/desktop/Code_Test.d/Test")
"""
Author: Jon Webb
Date:   March 27, 2017
"""
class Test
    """ This documents my class"""
    def __init(self,Data):
    def Sum(self):
        """ This documents a member function"""
        return (np.sum(self.Data))

我正在尝试使用它作为测试用例来学习如何使用Sphinx记录Python代码。我在代码所在的目录中运行sphinx-quickstart,并在快速入门设置期间将其声明为根目录。正如预期的那样,它会生成许多文件,包括_build_static_templateconf.pyindex.rst。我已按以下格式修改了index.rst文件,以使其识别出Test.py模块存在且包含Test类。

.. Test documentation master file, created by
   sphinx-quickstart on Mon Mar 27 14:28:47 2017.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Test's documentation!
================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

.. automodule:: Statistics
.. autoclass:: Test
    :members:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

但是,当我运行make html时,我收到以下警告WARNING: autofocus failed to import module 'Statistics'; the following exception was raised: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/sphinx/ext/autodoc.py", line 551, in import_object __import__(self.modname) File "/Users/jonwebb/desktop/Code_Test.d/Test/Statistics.py", line 7 class Test。换句话说,它似乎无法识别标题为Statistics.py的文件存在,因此无法找到Test类。我缺少什么以及如何让代码引入文档字符串并正确记录类和成员函数?

0 个答案:

没有答案