Sphinx doesn't find Python packages when using autodoc

15,164

I don't know what the "absolute path to testDoc" is, but from the Sphinx output I can see that the testDoc directory structure is testDoc/t/docs. The docs directory is where conf.py is.

For the module search path to be set up properly, you need to go two levels up from conf.py:

sys.path.insert(0, os.path.abspath("../.."))
Share:
15,164
rok
Author by

rok

Senior infra/software/devops engineer with a strong Python and Java background and a proven track record of delivering high quality solutions. Has particular interest in modern applications architectures which are containerized, orchestrated, highly available, scalable and fault-tolerant. Dives into the guts of a running system to fix issues everyone is happy to pass over. Have experience building PaaS in a private cloud from scratch. Successfully learned any necessary technology at any company and any position to cover the gaps whether it's on site, fully remotely or on customer site. Value provided to companies I worked at always greatly exceeded merely performing my duties.

Updated on July 01, 2022

Comments

  • rok
    rok almost 2 years

    I'm trying to create documentation for test Python project before doing it for the real project. My system : Win7 64 bit, python 2.7.5 64 bit.

    My project name is testDoc. It includes python pakage, named t, which includes 2 modules t1 and t2 and __init__.py.

    __init__.py contains:

    import t1
    import t2
    

    t1.py contains:

    '''
    Created on 27  2013
    
    @author: 
    '''
    
    class MyClass(object):
        '''
        Hi
        '''
    
    
        def __init__(self,selfparams):
            '''
            Constructor
            '''
            pass
    

    To create docs I run in the command line in testDoc:

    sphinx-apidoc -A "me" -F -o docs .
    

    Sphinx creates many files and it's ok according to Sphinx docs. Then, conf.py is modified

    sys.path.insert(0, os.path.abspath(absolute path to testDoc))
    

    I enter docs folder and type

    make html
    

    and get the following erroneous output:

    Making output directory...
    Running Sphinx v1.1.3
    loading pickled environment... not yet created
    building [html]: targets for 2 source files that are out of date
    updating environment: 2 added, 0 changed, 0 removed
    reading sources... [ 50%] index
    reading sources... [100%] t
    Traceback (most recent call last):
      File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 321, in impor
    t_object
        __import__(self.modname)
    ImportError: No module named t.__init__
    Traceback (most recent call last):
      File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 321, in impor
    t_object
        __import__(self.modname)
    ImportError: No module named t.t1
    Traceback (most recent call last):
      File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 321, in impor
    t_object
        __import__(self.modname)
    ImportError: No module named t.t2
    
    ...testDoc\t\docs\t.rst:7: WARNING: a
    autodoc can't import/find module 't.__init__', it reported error: "No module name
    d t.__init__", please check your spelling and sys.path
    ...testDoc\t\docs\t.rst:15: WARNING:
    autodoc can't import/find module 't.t1', it reported error: "No module named t.t
    1", please check your spelling and sys.path
    t...testDoc\t\docs\t.rst:23: WARNING:
    autodoc can't import/find module 't.t2', it reported error: "No module named t.t
    2", please check your spelling and sys.path
    looking for now-outdated files... none found
    pickling environment... done
    checking consistency... done
    preparing documents... done
    writing output... [ 50%] index
    writing output... [100%] t
    
    writing additional files... (0 module code pages) genindex search
    copying static files... done
    dumping search index... done
    dumping object inventory... done
    build succeeded, 3 warnings.
    
    Build finished. The HTML pages are in _build/html.
    

    What's wrong? Thanks.