2012-04-25 15 views
50

私はSphinxを使い始めようとしており、絶え間なく問題を抱えているようです。sphinx-buildが失敗する - autodocがモジュールをインポート/検索できない

コマンド:docs/sphinx-quickstart

私はすべての質問に答えると、すべてが正常に動作します。

コマンド:docs/ls

すべてが正常に見えます。結果:build Makefile source

コマンド:sphinx-build -d build/doctrees source build/html

動作するようです。私はindex.htmlファイルを開き、私が望むものの "シェル"を見ることができました。

実際のソースコードをsourceというフォルダに入れてみると、問題が発生します。

コマンド:sphinx-build -d build/doctrees ../ys_utils build/html

結果:

Making output directory... 
Running Sphinx v1.1.3 
loading pickled environment... not yet created 
No builder selected, using default: html 
loading intersphinx inventory from http://docs.python.org/objects.inv... 
building [html]: targets for 1 source files that are out of date 
updating environment: 1 added, 0 changed, 0 removed 
Traceback (most recent call last):                        
    File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object 
    __import__(self.modname) 
ImportError: No module named ys_utils 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object 
    __import__(self.modname) 
ImportError: No module named ys_utils.test_validate_ut 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object 
    __import__(self.modname) 
ImportError: No module named ys_utils.git_utils 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object 
    __import__(self.modname) 
ImportError: No module named setup.setup 

/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:4: WARNING: autodoc can't import/find module 'ys_utils', it reported error: "No module named ys_utils", please check your spelling and sys.path 
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:10: WARNING: autodoc can't import/find module 'ys_utils.test_validate_ut', it reported error: "No module named ys_utils.test_validate_ut", please check your spelling and sys.path 
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:12: WARNING: don't know which module to import for autodocumenting u'UnitTests' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name) 
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:18: WARNING: autodoc can't import/find module 'ys_utils.git_utils', it reported error: "No module named ys_utils.git_utils", please check your spelling and sys.path 
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:24: WARNING: autodoc can't import/find module 'setup.setup', it reported error: "No module named setup.setup", please check your spelling and sys.path 
WARNING: master file /home/ricomoss/workspace/nextgen/ys_utils/index.rst not found 
looking for now-outdated files... none found 
pickling environment... done 
checking consistency... /home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:: WARNING: document isn't included in any toctree 
done 
preparing documents... done 
writing output... [ 50%] index                         
Exception occurred: 
    File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/environment.py", line 1213, in get_doctree 
    f = open(doctree_filename, 'rb') 
IOError: [Errno 2] No such file or directory: '/home/ricomoss/workspace/nextgen/docs/build/doctrees/index.doctree' 
The full traceback has been saved in /tmp/sphinx-err-jjJ7gM.log, if you want to report the issue to the developers. 
Please also report this if it was a user error, so that a better error message can be provided next time. 
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>, 
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks! 

私は完全にスフィンクスに初心者やドキュメントのこの種の比較的新しいです。誰もが提案を提供できますか?

編集:

私はこれを処理するためにMakefileを使用できるようにしたいと思います。現時点では私のプロジェクトに2つのフォルダがあります。

nextgen/ls

docs ys_utils

私はys_utilsのためのHTMLと私は持っているつもりです他のすべてのモジュールを生成するnextgen/docs/Makefileを必要としています。

+0

'/ home/ricomoss/workspace/nextgen/docs/build/doctrees/index.doctree'は存在しないと思われます。それは存在しますか? –

+0

いいえ、そうではありません。この問題を解決するためにMakefileから何を追加(削除?)することはできますか? – Rico

答えて

1

私はtoctreeにファイルを追加しようとしたときにこれをやったと思います。私は:maxdepth行とファイル名の間に空白行を入れなかったからだと思います。

.. Animatrix Concepts documentation master file, created by 
    sphinx-quickstart on Thu Mar 22 18:06:15 2012. 
    You can adapt this file completely to your liking, but it should at least 
    contain the root `toctree` directive. 

Welcome to Animatrix Concepts documentation! 
============================================ 

Contents: 

.. toctree:: 
    :maxdepth: 2 

    stuff 


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

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

上記は私のindex.rstファイルです。 stuff.rstは、それと同じディレクトリにあります。

+2

これはどこに行くのですか?私は '/ docs/source'と'/ys_utils'に 'index.rst'を持っています。私はこれが 'docs'バージョンにあるはずですか? 'sphinx-quickstart'で作成されたデフォルトの' index.rst'ファイルを使用しています。 – Rico

+0

-1トレースバックから、モジュールが 'sys.path'にないことは明らかですので、autodocはそれらを見つけられません。 '.rst'ファイルが見つかります。 – bmu

52

Autodocはsys.pathにないため、モジュールを見つけることができません。

conf.pysys.pathにモジュールへのパスを含める必要があります。 conf.pyの先頭(sysのインポート直後)には、sys.path.insert()というステートメントがあります。

ところで、スフィンクスが作成したMakefileを使用してドキュメントを作成することができます。

make 

をご覧ください。

何かが試してみる前に、間違っていた場合:make htmlを実行する前に、

make clean 

conf.py

21

ちょうどあなたのプロジェクトフォルダへのパスを追加します。

sys.path.append('/home/workspace/myproj/myproj') 
+1

パスハードコーディングは、あなたの 'conf.py'でできることではありません。 – firegurafiku

+7

'/ app'、'/docs'のようなプロジェクト構造を持っているなら、 'sys.path.append(os.path.join(os.path.dirname(__ name__)) 'を使うかもしれません。 ')) ''あなたの '.rst'-fileに' .. automodule :: app'を使います。 – fnkr

+0

これは最適なソリューションです!ありがとう。また、ドキュメントがdocsにある場合はsys.path.append( '../')を追加する方がいいです。そうすれば、gitにコミットすれば誰でもローカルで実行できます。 – harishkashyap

0

スフィンクスは、私の通訳ではなく、スフィンクスに__import__(module_name)importlib.import_module(module_name)仕事の両方を実行している、非常にpython3互換性がありません。

私は、スフィンクスのマスターブランチをチェックし、インタープリタをMakefileのpython3.4に変更し、3.xシリーズで削除されたモジュールでエラーが発生しました。あなたはここに私の問題のレポートを見ることができます:

https://github.com/sphinx-doc/sphinx/issues/2046

0

あなたがそれらに埋め込まれたコードの出力が含まれる最初のドキュメントを生成するPweaveとnowebの書式設定を使用することができます。

<<echo=False>>= 
print("some text that will appear in the rst file") 
@ 

とPweaveは、それらのチャンクを実行し、あなたが、その後に使用することができた最初のファイルでの出力、それらを置き換えます:基本的に、あなたはこのようにマークされたチャンクに埋め込まれたPythonコードで、あなたの最初のファイルを書き込みますスフィンクス。見た目の詳細については、Pweave reST exampleを参照してください。

0

私は自分のスフィンクスコードを文書化するためにautodocを使用しようとしましたが、そのファイル内でクラスを作成しなかったので、私のファイルの1つをスキップします。このファイルは元々このようなものです:

""" 
testing autodoc - this should be first line in doc 
""" 
import simulator 
world = simulator.simulator() 
#some more code... 

このファイルは、スフィンクスによって決して文書化されませんでした。スフィンクスはクラスでそれらが文書を取得するためにすべてのファイルをラップする必要がありますように

""" 
testing autodoc - this should be first line in doc 
""" 
import simulator 

class runme(): 
    def __init__(self): 
    world = simulator.simulator() 
    #some more code... 


if __name__ == "__main__": 
    runme() 

だから、それはそう:それは文書化されるようにするには、私は、次の手順を実行しなければなりませんでした。あなたがスフィンクスがなぜ文書化していないのか理解しようと時間を費やしていたからです。

+0

index.rstファイルの関数を宣言して、自動的に医学的なdoctestを抽出するのに役立ちます。 '.. auto function :: a_function_name'はうまくいきます。 – Dilettant

0

os.path.append()のように聞こえますが、conf.pyのテンプレートに従うと、 sys.pathos.path.insert(0, ...)を使用して、ちょうどあなたが設定別のbulidsourceディレクトリを使用するようにsphinxプロジェクトを持っている場合は、その呼び出しが代わりにする必要があり、余分な.

import os 
import sys 
sys.path.insert(0, os.path.abspath('..')) 

を追加します。

sys.path.insert(0, os.path.abspath('../..'))