2013-07-28 13 views
15

Sto provando a creare documentazione per il progetto di prova Python prima di farlo per il progetto reale. Il mio sistema: Win7 64 bit, python 2.7.5 64 bit.Sphinx non trova i pacchetti Python quando utilizza l'autodoc

Il nome del mio progetto è testDoc. Include python pakage, denominato t, che include 2 moduli t1 e t2 e __init__.py.

__init__.py contiene:

import t1 
import t2 

t1.py contiene:

''' 
Created on 27 2013 

@author: 
''' 

class MyClass(object): 
    ''' 
    Hi 
    ''' 


    def __init__(self,selfparams): 
     ''' 
     Constructor 
     ''' 
     pass 

Per creare documenti ho eseguito nella riga di comando in testDoc:

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

Sfinge crea molti file e va bene secondo Sphinx d ocs. Poi, conf.py viene modificato

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

Entro documenti cartella e digito

make html 

e ottengo il seguente output errato:

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. 

Cosa c'è di sbagliato? Grazie.

+0

La mia ipotesi è che ci sia qualcosa di sbagliato con 'percorso assoluto testDoc'. Non puoi usare 'os.path.abspath (" .. ")'? – mzjn

+0

@mzjn Grazie. Tuttavia, lo stesso problema si verifica. – user1264304

risposta

19

Non so quale sia il "percorso assoluto per testDoc", ma dall'uscita Sphinx posso vedere che la struttura della directory testDoc è testDoc/t/docs. La directory docs è dove conf.py è.

Per il percorso di ricerca del modulo per impostare correttamente, è necessario andare due livelli su da conf.py:

sys.path.insert(0, os.path.abspath("../..")) 
+0

@ mzjn Grazie. Ha funzionato. Con il percorso assoluto no. – user1264304

+0

L'ho fatto, aggiungendo il percorso i moduli, ma ancora, compila e nessun modulo compare! Qualche idea ? –

+0

@PedroBraz: È difficile trovare un buon suggerimento. Ogni progetto è diverso e non so nulla dei tuoi. – mzjn

Problemi correlati